From 0081856c0c285fc8a3b9a7932475ae2bfa6b736d Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Fri, 16 Oct 2026 15:22:32 +0100 Subject: [PATCH] A constant's slice part may name another module's array constant constPart took the whole constant only by its bare name, by the length of its text; Widths.Wide failed. It now asks for the constant's own type, which a part of it, an element or a slice, hasn't. --- diff --git a/conform/run/EmptySliceConst.expect b/conform/run/EmptySliceConst.expect index 458d821..76ade09 100644 --- a/conform/run/EmptySliceConst.expect +++ b/conform/run/EmptySliceConst.expect @@ -3,3 +3,5 @@ wide 1 narrow 0 none 0 +Widths.Wide 3 +Widths.Narrow 0 diff --git a/conform/run/EmptySliceConst.raz b/conform/run/EmptySliceConst.raz index c2f89fe..cdebf65 100644 --- a/conform/run/EmptySliceConst.raz +++ b/conform/run/EmptySliceConst.raz @@ -10,7 +10,8 @@ None: []I64 = []; Wide: [][2]I32 = [[1100H, 115FH]]; Narrow: [][2]I32 = []; - Props: []Prop = [{name: "wide", runs: Wide}, {name: "narrow", runs: Narrow}, {name: "none", runs: []}]; + Props: []Prop = [{name: "wide", runs: Wide}, {name: "narrow", runs: Narrow}, {name: "none", runs: []}, + {name: "Widths.Wide", runs: Widths.Wide}, {name: "Widths.Narrow", runs: Widths.Narrow}]; proc sum(a: []I64): I64; var s: I64; i: INT; diff --git a/doc/compiler.md b/doc/compiler.md index e26fc0f..3d8542f 100644 --- a/doc/compiler.md +++ b/doc/compiler.md @@ -20,7 +20,7 @@ | `src/X64.raz` | 1,517 | 1,253 | The instruction encoder, jumps within a procedure, the assembler | | `src/Gen.raz` | 2,552 | 1,821 | The stack machine, for x86-64: values, operations, checks, calls, frames | | `src/Item.raz` | 2,037 | 1,651 | Items: types, constants, variables, operators, conversions, calls | -| `src/Parse.raz` | 4,175 | 3,616 | Declarations, statements, expressions, built-ins, recovery, warnings | +| `src/Parse.raz` | 4,176 | 3,615 | Declarations, statements, expressions, built-ins, recovery, warnings | | `src/Link.raz` | 381 | 298 | Tree shaking, layout, patching, the places | | `src/Elf.raz` | 431 | 344 | Static and dynamic ELF, symbol table, line numbers | | `src/Raz.raz` | 305 | 238 | The command line | diff --git a/src/Parse.raz b/src/Parse.raz index 8ef3307..1dea194 100644 --- a/src/Parse.raz +++ b/src/Parse.raz @@ -3234,9 +3234,10 @@ COPY(constBytes[off..off + INT(e.val)], Chunk.rodata[st..st + INT(e.val)]); end; elsif t^.form = Sym.fSlice then - if (e.mode # Item.mVar) or (e.obj = nil) or (e.obj^.cls # Sym.oConst) - or not (e.typ^.form in {Sym.fArray, Sym.fSlice}) - or (e.pos.b - e.pos.a # LEN(nameOf(e.obj^.name))) or not Sym.same(e.typ^.base, t^.base) then + (* the whole constant, here or another module's, not a part of + it, which has a type of its own: the element's, or a slice's *) + if (e.mode # Item.mVar) or (e.obj = nil) or (e.obj^.cls # Sym.oConst) or (e.typ # e.obj^.typ) + or not (e.typ^.form in {Sym.fArray, Sym.fSlice}) or not Sym.same(e.typ^.base, t^.base) then return Scan.markAt(e.pos, say1("a constant slice is a string, an array constant of its elements or [], found {}", Item.what(e))); end; if e.typ^.form = Sym.fArray then (* else an empty slice constant, whose bytes stay zero *) diff --git a/test/msg/EmptySliceConst.stderr b/test/msg/EmptySliceConst.stderr index 25f5ef2..6c04d33 100644 --- a/test/msg/EmptySliceConst.stderr +++ b/test/msg/EmptySliceConst.stderr @@ -1,2 +1,2 @@ -conform/run/EmptySliceConst.raz:34:18: index 0 is out of range for a length of 0 - in EmptySliceConst.main at conform/run/EmptySliceConst.raz:34:18: i = 0 +conform/run/EmptySliceConst.raz:35:18: index 0 is out of range for a length of 0 + in EmptySliceConst.main at conform/run/EmptySliceConst.raz:35:18: i = 0