mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-29 19:57:58 +00:00
handle typedesc params in VM (#22581)
* handle typedesc params in VM
fixes #15760
* add test
* fix getType(typedesc) test
(cherry picked from commit 2e4e2f8f50)
This commit is contained in:
18
tests/vm/ttypedesc.nim
Normal file
18
tests/vm/ttypedesc.nim
Normal file
@@ -0,0 +1,18 @@
|
||||
block: # issue #15760
|
||||
type
|
||||
Banana = object
|
||||
SpecialBanana = object
|
||||
|
||||
proc getName(_: type Banana): string = "Banana"
|
||||
proc getName(_: type SpecialBanana): string = "SpecialBanana"
|
||||
|
||||
proc x[T](): string =
|
||||
const n = getName(T) # this one works
|
||||
result = n
|
||||
|
||||
proc y(T: type): string =
|
||||
const n = getName(T) # this one failed to compile
|
||||
result = n
|
||||
|
||||
doAssert x[SpecialBanana]() == "SpecialBanana"
|
||||
doAssert y(SpecialBanana) == "SpecialBanana"
|
||||
@@ -1,10 +1,11 @@
|
||||
# bug #4462
|
||||
import macros
|
||||
import os
|
||||
|
||||
# bug #4462
|
||||
block:
|
||||
proc foo(t: typedesc) {.compileTime.} =
|
||||
assert sameType(getType(t), getType(int))
|
||||
assert sameType(getType(t), getType(typedesc[int]))
|
||||
assert sameType(getType(t), getType(type int))
|
||||
|
||||
static:
|
||||
foo(int)
|
||||
|
||||
Reference in New Issue
Block a user