You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using a custom AST for a mathematical modeling application. This led me to a compiler bug involving object variants and case switch.
The bug can be reproduced from the following minimal example below. The C code output from this example doesn't compile. Interestingly, it does compile if I remove if n.lag < 0: s.append(&"({$n.lag})")
Example
import strformat
typeNodeKind*=enum
nkBinary,
nkVariable,
nkExpression
CompiledNode*=refCompileNodeObjCompileNodeObj=objectcase kind*: NodeKind of nkExpression:
node*: CompiledNode of nkBinary:
op*: string
lhs*: CompiledNode
rhs*: CompiledNode of nkVariable:
root*: string
subscripts*: seq[string]
lag*: intprocappend(s: varstring, s2: string): varstring {.discardable.} = s.add(s2); return s
proctmpl*(s: varstring, n: CompiledNode): varstring {.discardable.} =case n.kind:
of nkBinary: s.tmpl(n.lhs).append(&"{n.op}").tmpl(n.rhs)
of nkExpression: s.tmpl(n.node)
of nkVariable:
s.append(n.root)
if n.lag <0: s.append(&"({$n.lag})")
return s
var n =CompiledNode(kind: nkBinary, op: "+", lhs: CompiledNode(kind: nkVariable, root: "a"), rhs: CompiledNode(kind: nkVariable, root: "b"))
var s: stringecho s.tmpl(n)
Current Output
@mminimal.nim.c:495:30: error: use of undeclared identifier 'T4_'; did you mean 'T6_'?
unsureAsgnRef((void**) (&(*T4_)), copyString((*T6_)));
^~~
T6_
@mminimal.nim.c:490:19: note: 'T6_' declared here
NimStringDesc** T6_;
^
1 error generated.
Additional information
Inspecting mminimal.nim.c reveals that the C code that fails to compile was emitted by the corresponding Nim line of nkExpression: s.tmpl(n.node).
$ nim -v
Nim Compiler Version 1.6.4 [MacOSX: amd64]
(also fails on WIndows 10: x86-64)
The text was updated successfully, but these errors were encountered:
I am using a custom AST for a mathematical modeling application. This led me to a compiler bug involving object variants and case switch.
The bug can be reproduced from the following minimal example below. The C code output from this example doesn't compile. Interestingly, it does compile if I remove
if n.lag < 0: s.append(&"({$n.lag})")
Example
Current Output
Additional information
Inspecting
mminimal.nim.c
reveals that the C code that fails to compile was emitted by the corresponding Nim lineof nkExpression: s.tmpl(n.node)
.The text was updated successfully, but these errors were encountered: