Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

var ref param doesn't work when it comes from an object member #12489

Closed
krux02 opened this issue Oct 22, 2019 · 0 comments
Closed

var ref param doesn't work when it comes from an object member #12489

krux02 opened this issue Oct 22, 2019 · 0 comments
Labels
VM see also `const` label

Comments

@krux02
Copy link
Contributor

krux02 commented Oct 22, 2019

Example

type
  MyObjectRef = ref object
    a,b: int

  MyContainerObject = ref object
    member: MyObjectRef

proc foobar(dst: var MyObjectRef) =
  dst = new(MyObjectRef)
  dst.a = 123
  dst.b = 321

proc test() =
  # when it comes from a var, it works
  var y: MyObjectRef
  foobar(y)
  echo y != nil
  # when it comes from a member, it fails on VM
  var x = new(MyContainerObject)
  foobar(x.member)
  echo x.member != nil

test()
static:
  test()

Current Output

Hint: scratch [Processing]
true
false
CC: stdlib_system.nim
CC: scratch.nim
Hint:  [Link]
Hint: operation successful (21928 lines compiled; 1.042 sec total; 25.594MiB peakmem; Dangerous Release Build) [SuccessX]
Hint: /tmp/scratch  [Exec]
true
true

Expected Output

Hint: scratch [Processing]
true
true
CC: stdlib_system.nim
CC: scratch.nim
Hint:  [Link]
Hint: operation successful (21928 lines compiled; 1.042 sec total; 25.594MiB peakmem; Dangerous Release Build) [SuccessX]
Hint: /tmp/scratch  [Exec]
true
true

Additional Information

@krux02 krux02 added the VM see also `const` label label Oct 22, 2019
krux02 added a commit to krux02/Nim that referenced this issue Oct 29, 2019
@Araq Araq closed this as completed in abe07eb Nov 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VM see also `const` label
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant