Skip to content

VM error when passing object field ref to proc(var T): var T #25210

@nitely

Description

@nitely

Nim Version

Nim Compiler Version 2.3.1 [Linux: amd64]
Compiled at 2025-09-25
Copyright (c) 2006-2025 by Andreas Rumpf

git hash: 9f74712
active boot switches: -d:release

Description

It used to work in Nim 2.0.8.

iterator it(x: var int): var int =
  yield x

proc it(x: var int): var int =
  x

proc main() =
  type Obj = object
    field: ref int
  var obj = Obj(field: new(int))
  obj.field[] = 123
  echo it(obj.field[]) # fails
  for x in it(obj.field[]): # fails
    echo x

static:
  main()

Current Output

Error: attempt to access a nil address kind: rkInt

Expected Output

123
123

Known Workarounds

No response

Additional Information

The iterator issue was found when using nim-stew.

Metadata

Metadata

Assignees

Labels

StatusVMsee also `const` label

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions