Skip to content

Commit

Permalink
give typedesc param nodes type T not typedesc[T] [backport:2.0] (nim-…
Browse files Browse the repository at this point in the history
…lang#23115)

fixes nim-lang#23112, fixes a mistake in
nim-lang#22581

This makes `getType(t)` where `t` is a typedesc param with value `T`
equal to `getType(T)`.

(cherry picked from commit 3224337)
  • Loading branch information
metagn authored and narimiran committed Jan 19, 2024
1 parent 9994b01 commit 4a1151d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion compiler/vmgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2114,7 +2114,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:
Expand Down
13 changes: 13 additions & 0 deletions tests/vm/ttypedesc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 1 addition & 2 deletions tests/vm/tvmmisc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4a1151d

Please sign in to comment.