Skip to content

Commit 7e6e6f5

Browse files
committed
Improve compilation for detached tree parts
1 parent a601192 commit 7e6e6f5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

compiler/compiler.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,10 @@ func (c *compiler) StringNode(node *ast.StringNode) {
403403
}
404404

405405
func (c *compiler) ConstantNode(node *ast.ConstantNode) {
406+
if node.Value == nil {
407+
c.emit(OpNil)
408+
return
409+
}
406410
c.emitPush(node.Value)
407411
}
408412

@@ -695,7 +699,9 @@ func (c *compiler) MemberNode(node *ast.MemberNode) {
695699
}
696700

697701
c.compile(base)
698-
if node.Optional {
702+
// If the field is optional, we need to jump over the fetch operation.
703+
// If no ChainNode (none c.chains) is used, do not compile the optional fetch.
704+
if node.Optional && len(c.chains) > 0 {
699705
ph := c.emit(OpJumpIfNil, placeholder)
700706
c.chains[len(c.chains)-1] = append(c.chains[len(c.chains)-1], ph)
701707
}

0 commit comments

Comments
 (0)