ttypedesc2.nim 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. # https://github.com/nim-lang/Nim/issues/7516
  29. import typetraits
  30. proc hasDefault1(T: type = int): auto = return T.name
  31. doAssert hasDefault1(int) == "int"
  32. doAssert hasDefault1(string) == "string"
  33. doAssert hasDefault1() == "int"
  34. proc hasDefault2(T = string): auto = return T.name
  35. doAssert hasDefault2(int) == "int"
  36. doAssert hasDefault2(string) == "string"
  37. doAssert hasDefault2() == "string"