mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-22 00:41:28 +00:00
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:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user