I'm getting some odd behavior that I don't understand. I've simplified it down 
to this example:
    
    
    type
      NodeKind = enum A, B
      
      Node = object
        case kind: NodeKind
        of A:
          children: seq[Node]
        of B:
          value: int  # <-------- this line
    
    const root = Node(kind: A, children: @[Node(), Node()])
    static: echo "COMPILETIME CHILDREN ", root.children.len
    echo "RUNTIME CHILDREN ", root.children.len
    
    
    Run

When run it produces this: 
    
    
    COMPILETIME CHILDREN 2
    RUNTIME CHILDREN 0
    
    
    Run

However if you change the marked line to discard: 
    
    
    COMPILETIME CHILDREN 2
    RUNTIME CHILDREN 2
    
    
    Run

Changing the const to var produces the correct result either way, but the 
actual code this is based on needs to be a const.

I'm not sure if this is a bug or if I'm just misunderstanding something

Reply via email to