Skip to content

=destroy doesn't work in VM or js #17237

@timotheecour

Description

@timotheecour

originally reported here: #17230 (comment)

=destroy should work the same on all backends otherwise assumptions are broken when using code written for a backend on another backend, leading to not just bugs but silent bugs.

Example 1

when true:
  type
    A = object
      id: int
    B = object
      a: A
  proc `=destroy`(a: var A) = echo a.id
  template main =
    var x = A(id: 1)
    var y = B(a: A(id: 2))
    `=destroy`(x)
    `=destroy`(y)
    echo "here"
  static: main()
  main()

nim r main

Current Output

both with and without --gc:arc:

ct:
1
here

rt:
1
2
here
2
1

Expected Output

ct:
1
2
here
2
1

rt:
1
2
here
2
1

Example 2

ditto with with -b:js

ct:
1
here

rt:
1
2
here

expected output: same as previous Expected Output

Additional Information

1.5.1 02f4464

related

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions