From ddf0eb5f71f0c0fed4b06c4cd17e1fb7f75f2d9a Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Mon, 26 Oct 2026 13:31:43 +0000 Subject: [PATCH] A var parameter given SYSTEM.ADR(b): help says write b, as for ADR(b) --- diff --git a/src/Item.raz b/src/Item.raz index 9dcfd65..8530c82 100644 --- a/src/Item.raz +++ b/src/Item.raz @@ -1974,19 +1974,21 @@ (* An address given where a var or const parameter of its type wants the variable itself, as ADR(b) for var b: Buf: an error that says what to - write instead, b for ADR(b) and p^ for a pointer p. Mostly met in + write instead, b for SYSTEM.ADR(b) or ADR(b), and p^ for a pointer p. Mostly met in programs written before the library took var (report 2026-10.33). *) proc givenAddress(const a: Item; p: ^Sym.Obj): ERROR; -var s, kind: []const U8; +var s, kind: []const U8; k: INT; begin if (a.typ^.form # Sym.fPtr) or (a.typ^.base = nil) or not Sym.same(a.typ^.base, p^.typ) then return nil; end; if p^.isConst then kind := "const"; else kind := "var"; end; s := Diag.source(a.pos); - if (LEN(s) > 5) and (s[0..4] = "ADR(") and (s[LEN(s) - 1] = ')') then + k := 0; (* past SYSTEM., as ADR is written in a module that imports it *) + if (LEN(s) > 7) and (s[0..7] = "SYSTEM.") then k := 7; end; + if (LEN(s) > k + 5) and (s[k..k + 4] = "ADR(") and (s[LEN(s) - 1] = ')') then s := Diag.say("write {} for {}: the parameter is the variable itself, not its address", - [Fmt.str(s[4..LEN(s) - 1]), Fmt.str(s)]); + [Fmt.str(s[k + 4..LEN(s) - 1]), Fmt.str(s)]); else s := Diag.say("write {}^ for {}: the parameter is the variable itself, not a pointer to it", [Fmt.str(s), Fmt.str(s)]); diff --git a/test/err/VarGivenAddress.err b/test/err/VarGivenAddress.err index e0c0918..8b1c204 100644 --- a/test/err/VarGivenAddress.err +++ b/test/err/VarGivenAddress.err @@ -1,13 +1,13 @@ -test/err/VarGivenAddress.raz:9:7: error: a var parameter takes B, found its address - 9 | f(ADR(b)); - | ^^^^^^ -help: write b for ADR(b): the parameter is the variable itself, not its address test/err/VarGivenAddress.raz:10:7: error: a var parameter takes B, found its address - 10 | f(p); + 10 | f(SYSTEM.ADR(b)); + | ^^^^^^^^^^^^^ +help: write b for SYSTEM.ADR(b): the parameter is the variable itself, not its address +test/err/VarGivenAddress.raz:11:7: error: a var parameter takes B, found its address + 11 | f(p); | ^ help: write p^ for p: the parameter is the variable itself, not a pointer to it -test/err/VarGivenAddress.raz:11:12: error: a const parameter takes B, found its address - 11 | _ := g(ADR(b)); - | ^^^^^^ -help: write b for ADR(b): the parameter is the variable itself, not its address +test/err/VarGivenAddress.raz:12:12: error: a const parameter takes B, found its address + 12 | _ := g(SYSTEM.ADR(b)); + | ^^^^^^^^^^^^^ +help: write b for SYSTEM.ADR(b): the parameter is the variable itself, not its address raz: 3 errors