raz / commit 384eba2a

commit
384eba2aac9c88ce1ffac84bcf32c87507e54f44
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
d141d687
A code procedure's body has a scope of its own: a name it uses before its declaration is one error, not two

patch · log

3 files changed, +26 -2

src/Parse.raz (history) modified +8 -2

@@ -3516,7 +3516,7 @@
35163516 end;
35173517
35183518 proc codeBody(p: PObj; sig: PType; at: Diag.Pos): ERROR;
3519-var q: PObj; ni, nf: INT;
3519+var q: PObj; ni, nf: INT; err: ERROR;
35203520 begin
35213521 ni := 0; nf := 0;
35223522 q := sig^.fields;
@@ -3546,7 +3546,13 @@
35463546 return Scan.markAt(at, "a code procedure returns a single value");
35473547 end;
35483548 end;
3549- try Gen.codeProc(p^.chunk, asmConst, asmName);
3549+ (* in a scope of its own, so that a name it uses and isn't declared,
3550+ declared then as poison, is gone at its end, as a procedure's
3551+ locals are, and doesn't clash with a declaration after it *)
3552+ try Sym.openScope(Sym.newScope());
3553+ err := Gen.codeProc(p^.chunk, asmConst, asmName);
3554+ Sym.closeScope;
3555+ if err # nil then return err; end;
35503556 (* a square root of one real, of its own kind, is made in place *)
35513557 q := sig^.fields;
35523558 if (q # nil) and (q^.next = nil) and not q^.isVar and (q^.typ^.form = Sym.fReal)

test/err/AsmNameLater.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+test/err/AsmNameLater.raz:7:15: error: later isn't declared
2+ 7 | lea rcx, [later];
3+ | ^^^^^
4+raz: 1 error

test/err/AsmNameLater.raz (history) added +14 -0

@@ -0,0 +1,14 @@
1+module AsmNameLater;
2+(* A name a code procedure uses before it is declared is an error once:
3+ its poison stays in the code procedure's scope, not the module's. *)
4+import SYSTEM;
5+proc f;
6+code
7+ lea rcx, [later];
8+ ret;
9+end f;
10+proc later;
11+begin end;
12+proc main*;
13+begin f(); end;
14+end AsmNameLater.