Summary
A ranged cell inside a block-layout (multi-line) array literal aborts with an
internal compiler error. The inline equivalents of the same literals compile and
produce correct output, so this is specific to block layout.
Reproduce
1. No function call involved
t.spt
arr = [10 20 30]
i = 0:3
b = [
[arr[i]]
]
"B: -b"
💥 internal compiler error: internal: ranged array access reached scalar lowering without an iterator loop
2. With a call
lib.pt
res = Pair(x)
res = [x x]
t.spt
arr = [10 20 30]
i = 0:3
b = [
[Pair(arr[i])]
]
"B: -b"
💥 internal compiler error: runtime error: index out of range [0] with length 0
compiler/array_nd.go:64
compiler/array_nd.go:63
The inline forms are correct
b = [[arr[i]]] # B: [ \n 10 20 30 \n ] correct
b = [[Sc(i)] [Sc(i)]] # B: [ \n 0 2 4 \n 0 2 4 \n ] correct
b = [Sc(i)] # B: [0 2 4] correct
So the range driver, the collector, and the call specialization all work; only
block-layout cell lowering does not establish the iterator loop.
Note for whoever picks this up
compileArrayValuedCell (compiler/array_nd.go:64) indexes compileExpression(...)[0]
with no length check, which is what turns case 2 into a panic. Adding a nil-guard
there is not the fix. The recorded error at that point is
function Pair not found for argument types [I64], which is itself spurious —
Pair(I64) plainly exists and p = Pair(5) compiles fine. Surfacing it would accuse
correct user code instead of reporting the real problem. Case 1 shows the underlying
defect with no call involved at all: block-layout cells reach scalar lowering without
an iterator loop.
Scope
Pre-existing. Both cases reproduce identically on 9fca83a and on the current branch
tip, so this is not a regression from any recent PR.
Summary
A ranged cell inside a block-layout (multi-line) array literal aborts with an
internal compiler error. The inline equivalents of the same literals compile and
produce correct output, so this is specific to block layout.
Reproduce
1. No function call involved
t.spt2. With a call
lib.ptt.sptThe inline forms are correct
So the range driver, the collector, and the call specialization all work; only
block-layout cell lowering does not establish the iterator loop.
Note for whoever picks this up
compileArrayValuedCell(compiler/array_nd.go:64) indexescompileExpression(...)[0]with no length check, which is what turns case 2 into a panic. Adding a nil-guard
there is not the fix. The recorded error at that point is
function Pair not found for argument types [I64], which is itself spurious —Pair(I64)plainly exists andp = Pair(5)compiles fine. Surfacing it would accusecorrect user code instead of reporting the real problem. Case 1 shows the underlying
defect with no call involved at all: block-layout cells reach scalar lowering without
an iterator loop.
Scope
Pre-existing. Both cases reproduce identically on
9fca83aand on the current branchtip, so this is not a regression from any recent PR.