ttypedesc2.nim 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. discard """
  2. output: '''(x: 'a')'''
  3. """
  4. type
  5. Bar[T] = object
  6. x: T
  7. proc infer(T: typeDesc): Bar[T] = Bar[T](x: 'a')
  8. let foo = infer(char)
  9. echo foo
  10. when true:
  11. # bug #1783
  12. type
  13. uoffset_t* = uint32
  14. FlatBufferBuilder* = object
  15. Array* [T] = object
  16. o*: uoffset_t
  17. len*: int
  18. data*: ptr UncheckedArray[T]
  19. proc ca* (fbb: ptr FlatBufferBuilder, T: typedesc, len: int): Array[T] {.noinit.} =
  20. result.len = len
  21. var fbb: ptr FlatBufferBuilder
  22. let boolarray = ca(fbb, bool, 2)
  23. let boolarray2 = fbb.ca(bool, 2)
  24. # bug #1664
  25. type Point[T] = tuple[x, y: T]
  26. proc origin(T: typedesc): Point[T] = discard
  27. discard origin(int)
  28. block: # issue #12704
  29. const a = $("a", "b")
  30. proc fun() =
  31. const str = $int
  32. let b = $(str, "asdf")
  33. fun()
  34. # https://github.com/nim-lang/Nim/issues/7516
  35. import typetraits
  36. block: #issue #12704
  37. const a = $("a", "b")
  38. proc fun() =
  39. const str = name(int)
  40. let b = $(str, "asdf")
  41. fun()
  42. proc hasDefault1(T: type = int): auto = return T.name
  43. doAssert hasDefault1(int) == "int"
  44. doAssert hasDefault1(string) == "string"
  45. doAssert hasDefault1() == "int"
  46. proc hasDefault2(T = string): auto = return T.name
  47. doAssert hasDefault2(int) == "int"
  48. doAssert hasDefault2(string) == "string"
  49. doAssert hasDefault2() == "string"
  50. # bug #9195
  51. type
  52. Error = enum
  53. erA, erB, erC
  54. Result[T, U] = object
  55. x: T
  56. u: U
  57. PB = object
  58. proc decodeUVarint*(itzzz: typedesc[SomeUnsignedInt],
  59. data: openArray[char]): Result[itzzz, Error] =
  60. result = Result[itzzz, Error](x: 0, u: erC)
  61. discard decodeUVarint(uint32, "abc")
  62. type
  63. X = object
  64. Y[T] = object
  65. proc testObj(typ: typedesc[object]): Y[typ] =
  66. discard
  67. discard testObj(X)
  68. #bug 12804
  69. import typetraits
  70. discard int.name[0]