give typedesc param nodes type T not typedesc[T] [backport:2.0] (#23115)

fixes https://github.com/nim-lang/Nim/issues/23112, fixes a mistake in
https://github.com/nim-lang/Nim/pull/22581

This makes `getType(t)` where `t` is a typedesc param with value `T`
equal to `getType(T)`.
This commit is contained in:
metagn
2024-01-18 16:50:36 +03:00
committed by GitHub
parent 473f259268
commit 3224337550
3 changed files with 15 additions and 3 deletions

View File

@@ -2124,7 +2124,7 @@ proc gen(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags = {}) =
genRdVar(c, n, dest, flags)
of skParam:
if s.typ.kind == tyTypeDesc:
genTypeLit(c, s.typ, dest)
genTypeLit(c, s.typ.skipTypes({tyTypeDesc}), dest)
else:
genRdVar(c, n, dest, flags)
of skProc, skFunc, skConverter, skMacro, skTemplate, skMethod, skIterator:

View File

@@ -16,3 +16,16 @@ block: # issue #15760
doAssert x[SpecialBanana]() == "SpecialBanana"
doAssert y(SpecialBanana) == "SpecialBanana"
import macros
block: # issue #23112
type Container = object
foo: string
proc canBeImplicit(t: typedesc) {.compileTime.} =
let tDesc = getType(t)
doAssert tDesc.kind == nnkObjectTy
static:
canBeImplicit(Container)

View File

@@ -4,8 +4,7 @@ import os
# bug #4462
block:
proc foo(t: typedesc) {.compileTime.} =
assert sameType(getType(t), getType(typedesc[int]))
assert sameType(getType(t), getType(type int))
assert sameType(getType(t), getType(int))
static:
foo(int)