Skip to content

Generic overload with ref object of RootObj type param not called; regression in Nim 2.0.16/version-2-0 #25166

@nitely

Description

@nitely

Nim Version

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

active boot switches: -d:release

Description

The overload won't work when ref object of RootObj is the first parameter, otherwise it works.

type Obj = ref object of RootObj

proc foo(s: Obj, x: SomeFloat) =
  echo "SomeFloat"
template foo(s: Obj, x: auto) =
  echo "auto"

foo(Obj(), 1.23)

proc bar[T: SomeFloat](s: Obj, x: T) =
  echo "SomeFloat"
proc bar[T](s: Obj, x: T) =
  echo "any"

bar(Obj(), 1.23)

# the following works

proc baz[T: SomeFloat](x: T, s: Obj) =
  echo "SomeFloat"
proc baz[T](x: T, s: Obj) =
  echo "any"

baz(1.23, Obj())

type Obj2 = ref object

proc quz[T: SomeFloat](s: Obj2, x: T) =
  echo "SomeFloat"
proc quz[T](s: Obj2, x: T) =
  echo "any"

quz(Obj2(), 1.23)

Current Output

auto
any
SomeFloat
SomeFloat

Expected Output

SomeFloat
SomeFloat
SomeFloat
SomeFloat

Known Workarounds

No response

Additional Information

works as expected in Nim 2.0.8, 2.2.4 and devel
the regression is present in 2.0.10 to 2.0.16 and version-2-0 branch (commit edeac84)

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