raz / commit ddf0eb5f

commit
ddf0eb5f71f0c0fed4b06c4cd17e1fb7f75f2d9a
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
04d8e1a9
A var parameter given SYSTEM.ADR(b): help says write b, as for ADR(b)

patch · log

2 files changed, +15 -13

src/Item.raz (history) modified +6 -4

@@ -1974,19 +1974,21 @@
19741974
19751975 (* An address given where a var or const parameter of its type wants the
19761976 variable itself, as ADR(b) for var b: Buf: an error that says what to
1977- write instead, b for ADR(b) and p^ for a pointer p. Mostly met in
1977+ write instead, b for SYSTEM.ADR(b) or ADR(b), and p^ for a pointer p. Mostly met in
19781978 programs written before the library took var (report 2026-10.33). *)
19791979 proc givenAddress(const a: Item; p: ^Sym.Obj): ERROR;
1980-var s, kind: []const U8;
1980+var s, kind: []const U8; k: INT;
19811981 begin
19821982 if (a.typ^.form # Sym.fPtr) or (a.typ^.base = nil) or not Sym.same(a.typ^.base, p^.typ) then
19831983 return nil;
19841984 end;
19851985 if p^.isConst then kind := "const"; else kind := "var"; end;
19861986 s := Diag.source(a.pos);
1987- if (LEN(s) > 5) and (s[0..4] = "ADR(") and (s[LEN(s) - 1] = ')') then
1987+ k := 0; (* past SYSTEM., as ADR is written in a module that imports it *)
1988+ if (LEN(s) > 7) and (s[0..7] = "SYSTEM.") then k := 7; end;
1989+ if (LEN(s) > k + 5) and (s[k..k + 4] = "ADR(") and (s[LEN(s) - 1] = ')') then
19881990 s := Diag.say("write {} for {}: the parameter is the variable itself, not its address",
1989- [Fmt.str(s[4..LEN(s) - 1]), Fmt.str(s)]);
1991+ [Fmt.str(s[k + 4..LEN(s) - 1]), Fmt.str(s)]);
19901992 else
19911993 s := Diag.say("write {}^ for {}: the parameter is the variable itself, not a pointer to it",
19921994 [Fmt.str(s), Fmt.str(s)]);

test/err/VarGivenAddress.err (history) modified +9 -9

@@ -1,13 +1,13 @@
1-test/err/VarGivenAddress.raz:9:7: error: a var parameter takes B, found its address
2- 9 | f(ADR(b));
3- | ^^^^^^
4-help: write b for ADR(b): the parameter is the variable itself, not its address
51 test/err/VarGivenAddress.raz:10:7: error: a var parameter takes B, found its address
6- 10 | f(p);
2+ 10 | f(SYSTEM.ADR(b));
3+ | ^^^^^^^^^^^^^
4+help: write b for SYSTEM.ADR(b): the parameter is the variable itself, not its address
5+test/err/VarGivenAddress.raz:11:7: error: a var parameter takes B, found its address
6+ 11 | f(p);
77 | ^
88 help: write p^ for p: the parameter is the variable itself, not a pointer to it
9-test/err/VarGivenAddress.raz:11:12: error: a const parameter takes B, found its address
10- 11 | _ := g(ADR(b));
11- | ^^^^^^
12-help: write b for ADR(b): the parameter is the variable itself, not its address
9+test/err/VarGivenAddress.raz:12:12: error: a const parameter takes B, found its address
10+ 12 | _ := g(SYSTEM.ADR(b));
11+ | ^^^^^^^^^^^^^
12+help: write b for SYSTEM.ADR(b): the parameter is the variable itself, not its address
1313 raz: 3 errors