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`
This commit is contained in:
ringabout
2026-02-23 20:40:31 +08:00
committed by GitHub
parent 6badeb1b4d
commit e58acc2e1e
2 changed files with 15 additions and 1 deletions

View File

@@ -2049,7 +2049,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)