diff options
| author | 2026-10-14 16:11:59 +0330 | |
|---|---|---|
| committer | 2026-10-14 16:11:59 +0330 | |
| commit | 19cdaa91b74da17a78809433ff7e6a2c084d8385 (patch) | |
| tree | 619993ef12f3ce7f057843a01520f3079b6bacd5 /src | |
| parent | fndef: a second definition of a function in the same module is 'is defined tw... (diff) | |
fndef: a prototype after a definition in the same module keeps the definition (appendix b.2.4)
Diffstat (limited to 'src')
| -rw-r--r-- | src/compiler/decl.zc | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/compiler/decl.zc b/src/compiler/decl.zc index 6794373..67aceb1 100644 --- a/src/compiler/decl.zc +++ b/src/compiler/decl.zc @@ -280,16 +280,17 @@ int body() { // into stype, checked against any earlier prototype or prescan result, and // where the o3 region for an o3 function is handed to the core) int fndef(int chk, int rty, int ret, int n) { - int s, np = 0, tags = 0, t, sig, i; char*[24] pn; word[24] pt; word[24] pty; int typed = 0, ft, explicit_rty = !!rty, o3f = o3nxt, lo, hi, pk, lt, lend, lfl = tline; + int s, np = 0, tags = 0, t, sig, i; char*[24] pn; word[24] pt; word[24] pty; int typed = 0, ft, explicit_rty = !!rty, o3f = o3nxt, lo, hi, pk, lt, lend, lfl = tline, redef; o3nxt = 0; if (rty || ntp) typed = 1; if (!dnm) dnm = n; s = lookup(n); - if (s >= ubase && skind[s] == K_FN && (sflag[s] & F_DEF) && !(sflag[s] & F_TPL) && !ginst && !ntp) { // appendix b.2.3: the same name in the same module + redef = 0; // a function this module already defined: a prototype after it keeps it (b.2.4), a second body is defined twice (b.2.3) + if (s >= ubase && skind[s] == K_FN && (sflag[s] & F_DEF) && !(sflag[s] & F_TPL) && !ginst && !ntp) { word qn = n; if (module_name) qn = module_symbol(n); - if (rt.eq_w(sname[s], qn)) serrn(n, "is defined twice"); + redef = rt.eq_w(sname[s], qn); } - if (s < 0 || s < ubase || skind[s] != K_FN || (sflag[s] & F_DEF)) { + if (!redef && (s < 0 || s < ubase || skind[s] != K_FN || (sflag[s] & F_DEF))) { s = addsym(n, K_FN, 0); sflag[s] = 0; } |
