Crash of compiler on array type check
The following code snippet crashes compiler:
type StringArray[N:int] = array[N, string]
let a = ["one", "two"]
echo a is StringArray
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
Small note: StringArray[N:int] or StringArray[N] does not make difference, compiler crashes in exactly the same way
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
Thanks Zah for clarification
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 why you didn't make a PR for https://github.com/cooldome/Nim/commit/6de61b68d7abfa22c642db90253a7b6f0deddaac ?
now it's 2022