Closed metagn closed 3 years ago
I compared the transforms of this with and without the kind, turns out the access of field
is wrapped in an nkCheckedFieldExpr
in one and not the other. the analyseIfAddressTaken
proc in semexprs.nim handles that so I added an unwrap case (doesn't feel a 100% right) but seems less terrible than putting an if guard for poor code gen. 🤷🏽
PR forth coming.
Encountered in nimscript. The issue seems to be that fields in object variant branches break when converting to
var T
.Example
Current Output
Expected Output
compiles
Possible Solution
As an immediate solution, if you change this line in
opcLdObj
:https://github.com/nim-lang/Nim/blob/6e267d28b3459aa447cae07ba61209438977cd5c/compiler/vm.nim#L714
to this line below it in
opcLdObjAddr
:https://github.com/nim-lang/Nim/blob/6e267d28b3459aa447cae07ba61209438977cd5c/compiler/vm.nim#L730
it works. Maybe the wrong VM opcode is getting generated, but it's better to be safe than crashing the compiler.
Additional Information