Skip to content

opcLdDeref (eg via addr) gives wrong results in inside static block #13887

@timotheecour

Description

@timotheecour

opcLdDeref gives wrong results in VM inside static block

Example 1

when true: # D20200405T172240
  # proc fun() = # would work
  template fun() = # fails
    var s = @[10,11,12]
    let z = s[0].addr
    doAssert z[] == 10
    z[] = 100
    doAssert z[] == 100
    doAssert s[0] == 100 # fails here
  static: fun() # fails
  fun() # would work

Current Output

doAssert s[0] == 100 fails

Expected Output

works

Example 2

shows that pointer is conflated for value:

  template fun() =
    var s = @[10,11,12]
    echo cast[int](s[0].addr) # 4323682360
    let z = s[0].addr 
    echo cast[int](z) # 10 => BUG
  static: fun() # fails

Example 3

when true: # D20200405T172849:here
  template fun() =
  # proc fun() = # would work
    var s = @[10.1,11.2,12.3]
    echo cast[int](s[0].addr)
    let z = s[0].addr
    echo cast[int](z)
  static: fun() # fails

Error: unhandled exception: 'intVal' is not accessible using discriminant 'kind' of type 'TNode' [FieldError]

Possible Solution

Additional Information

Metadata

Metadata

Assignees

No one assigned

    Labels

    const`const x=expr` or `static: stmt`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions