ttypedesc.nim 716 B

1234567891011121314151617181920212223242526272829303132
  1. block: # issue #15760
  2. type
  3. Banana = object
  4. SpecialBanana = object
  5. proc getName(_: type Banana): string = "Banana"
  6. proc getName(_: type SpecialBanana): string = "SpecialBanana"
  7. proc x[T](): string =
  8. const n = getName(T) # this one works
  9. result = n
  10. proc y(T: type): string =
  11. const n = getName(T) # this one failed to compile
  12. result = n
  13. doAssert x[SpecialBanana]() == "SpecialBanana"
  14. doAssert y(SpecialBanana) == "SpecialBanana"
  15. import macros
  16. block: # issue #23112
  17. type Container = object
  18. foo: string
  19. proc canBeImplicit(t: typedesc) {.compileTime.} =
  20. let tDesc = getType(t)
  21. doAssert tDesc.kind == nnkObjectTy
  22. static:
  23. canBeImplicit(Container)