fixes #25005; new doesn't work with ref object (#25532)

fixes #25005

In `semTypeIdent`, when resolving a typedesc parameter inside a generic
instantiation, the code took a shortcut: it returned the symbol of the
element type (`bound = result.typ.elementType.sym`). However, for
generic types like `RpcResponse[T] = ref object`, the instantiated
object type (e.g., `RpcResponse:ObjectType[string]`) is a copy with a
new type ID but still points to the same symbol as the uninstantiated
generic body type. That symbol's .typ refers to the original
uninstantiated type, which still contains unresolved generic params `T`

(cherry picked from commit e58acc2e1e)
This commit is contained in:
ringabout
2026-02-23 20:40:31 +08:00
committed by narimiran
parent 40a3a6b8e7
commit 5ec6391124
2 changed files with 15 additions and 1 deletions

View File

@@ -2006,7 +2006,9 @@ proc semTypeIdent(c: PContext, n: PNode): PSym =
# proc signature for example
if c.inGenericInst > 0:
let bound = result.typ.elementType.sym
if bound != nil: return bound
# the symbol may still point to the uninstantiated generic body type
if bound != nil and bound.typ == result.typ.elementType:
return bound
return result
if result.typ.sym == nil:
localError(c.config, n.info, errTypeExpected)

View File

@@ -902,3 +902,15 @@ block: # issue #25494
a, b, c
foo[MyEnum]()
block: # issue #25005
type
RpcResponse[T] = ref object
result: T
func testit[T](p: var ref T) =
p = new(T)
var v: RpcResponse[string]
testit(v)