It looks like a bug caused by a combination of a var parameter assignment , a case expression, a noreturn procedure, and CTFE:
# test.nim
proc raiseError(msg: string) {.noreturn.} = raise newException(Defect, msg)
proc change(v: var int, s: string) =
v =
case s:
of "A": 11
else: raiseError("invalid value")
static:
var a: int
a.change("A")
echo(a)
$ nim c test.nim
Hint: used config file '/home/japp/.choosenim/toolchains/nim-1.6.10/config/nim.cfg' [Conf]
Hint: used config file '/home/japp/.choosenim/toolchains/nim-1.6.10/config/config.nims' [Conf]
.........................................................fatal.nim(54) sysFatal
Error: unhandled exception: field 'intVal' is not accessible for type 'TFullReg' using 'kind = rkNode' [FieldDefect]
Is it a reason to file an issue?It mentioned rkNode, so it seems to be an internal error, a compiler bug. However, I don't think the code is valid.
v =
case s:
of "A": 11
else: raiseError("invalid value")
As raiseError doesn't return int, the compiler will think that you're assigning nothing to v if s is not "A".
Try to change it to
v =
case s:
of "A":
11
else:
raiseError("invalid value")
0
It should have checked for {.noreturn.} but it didn't.
Not exactly. This compiles well: https://play.nim-lang.org/#ix=4gXj
# test.nim
proc raiseError(msg: string) {.noreturn.} = raise newException(Defect, msg)
proc change(v: var int, s: string) =
let tmp =
case s:
of "A": 11
else: raiseError("invalid value")
v = tmp
static:
var a: int
a.change("A")
echo(a)