Nim icon indicating copy to clipboard operation
Nim copied to clipboard

Crash of compiler on array type check

Open cooldome opened this issue 8 years ago • 7 comments

The following code snippet crashes compiler:

type StringArray[N:int] = array[N, string]
let a = ["one", "two"]
echo a is StringArray

cooldome avatar May 07 '17 10:05 cooldome

Compiler crash stacktrace


Error: internal error: invalid kind for last(tyAnything)
Traceback (most recent call last)
nim.nim(121)             nim
nim.nim(77)              handleCmdLine
main.nim(163)            mainCommand
main.nim(74)             commandCompileToC
modules.nim(240)         compileProject
modules.nim(180)         compileModule
passes.nim(215)          processModule
passes.nim(135)          processTopLevelStmt
sem.nim(536)             myProcess
sem.nim(508)             semStmtAndGenerateGenerics
semstmts.nim(1679)       semStmt
semexprs.nim(828)        semExprNoType
semexprs.nim(2268)       semExpr
semexprs.nim(1905)       semMagic
semexprs.nim(811)        semDirectOp

cooldome avatar May 07 '17 11:05 cooldome

Small note: StringArray[N:int] or StringArray[N] does not make difference, compiler crashes in exactly the same way

cooldome avatar May 07 '17 11:05 cooldome

We should fix the compiler crash here, but your code is not correct. You need to use the static[int] type like this:

type StringArray[N: static[int]] = array[N, string]
let a = ["one", "two"]
echo a is StringArray

zah avatar May 07 '17 12:05 zah

Thanks Zah for clarification

cooldome avatar May 07 '17 17:05 cooldome

I though of it once again, shouldn't this work?

type StringArray[N] = array[N, string]
let a = ["one", "two"]
echo a is StringArray`

It crashes the same way with exactly the same stacktrace. Looks like it is not only error message problem. At least there is a simple workaround

cooldome avatar May 08 '17 08:05 cooldome

@cooldome why you didn't make a PR for https://github.com/cooldome/Nim/commit/6de61b68d7abfa22c642db90253a7b6f0deddaac ?

ghost avatar Oct 20 '17 13:10 ghost

now it's 2022

bung87 avatar Sep 18 '22 19:09 bung87