From c467532484fee6e0bf8aabb00e9bd41beb8f960d Mon Sep 17 00:00:00 2001 From: metagn Date: Fri, 13 Jun 2025 01:03:02 +0300 Subject: [PATCH] don't set sym of generic param type value to generic param sym (#24995) fixes #23713 `linkTo` normally sets the sym of the type as well as the type of the sym, but this is not wanted for custom pragmas as it would look up the definition of the generic param and not the definition of its value. I don't see a practical use for this either. (cherry picked from commit 7701b3c7e6f6c640a89cc445b40f466834ab4fcf) --- compiler/semexprs.nim | 8 ++++++-- tests/pragmas/tgenericparamcustompragma.nim | 13 +++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/pragmas/tgenericparamcustompragma.nim diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index a9cb598262..1c1cbdec99 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1345,7 +1345,9 @@ proc readTypeParameter(c: PContext, typ: PType, # This seems semantically correct and then we'll be able # to return the section symbol directly here let foundType = makeTypeDesc(c, def[2].typ) - return newSymNode(copySym(def[0].sym, c.idgen).linkTo(foundType), info) + let s = copySym(def[0].sym, c.idgen) + s.typ = foundType + return newSymNode(s, info) of nkConstSection: for def in statement: @@ -1370,7 +1372,9 @@ proc readTypeParameter(c: PContext, typ: PType, return c.graph.emptyNode else: let foundTyp = makeTypeDesc(c, rawTyp) - return newSymNode(copySym(tParam.sym, c.idgen).linkTo(foundTyp), info) + let s = copySym(tParam.sym, c.idgen) + s.typ = foundTyp + return newSymNode(s, info) return nil diff --git a/tests/pragmas/tgenericparamcustompragma.nim b/tests/pragmas/tgenericparamcustompragma.nim new file mode 100644 index 0000000000..d629f49324 --- /dev/null +++ b/tests/pragmas/tgenericparamcustompragma.nim @@ -0,0 +1,13 @@ +# issue #23713 + +import std/macros + +template p {.pragma.} + +type + X {.p.} = object + + Y[T] = object + t: T + +doAssert Y[X].T.hasCustomPragma(p)