Skip to content

No cursor inference for ref types #25334

@nitely

Description

@nitely

Nim Version

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

git hash: 2d0b62a
active boot switches: -d:release

Description

It seems there is no cursor inference for refs that'd avoid the ref count overhead, is this intended?

type Foo = ref object

proc newFoo(): Foo =
  Foo()

proc bar(foo: Foo) =
  let baz = foo
  echo repr baz
  echo repr foo

proc main() =
  let foo = newFoo()
  bar(foo)

main()

Expands to:

var
  baz
  :tmpD
  :tmpD_1
try:
  `=copy`(baz, foo)
  echo [
    :tmpD = repr baz
    :tmpD]
  echo [
    :tmpD_1 = repr foo
    :tmpD_1]
finally:
  `=destroy`(:tmpD_1)
  `=destroy`(:tmpD)
  `=destroy_1`(baz)

Current Output


Expected Output


Known Workarounds

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions