toverloading_typedesc.nim 665 B

123456789101112131415161718192021222324
  1. discard """
  2. exitcode: 0
  3. """
  4. import moverloading_typedesc
  5. import tables
  6. type
  7. LFoo = object
  8. LBar = object
  9. when isMainModule:
  10. doAssert FBar.new() == 3
  11. proc new(_: typedesc[LFoo]): int = 0
  12. proc new[T](_: typedesc[T]): int = 1
  13. proc new*(_: typedesc[seq[Table[int, seq[Table[int, typedesc]]]]]): int = 7
  14. doAssert LFoo.new() == 0 # Tests selecting more precise type
  15. doAssert LBar.new() == 1 # Tests preferring function from local scope
  16. doAssert FBar.new() == 1
  17. doAssert FFoo.new() == 2 # Tests selecting more precise type from other module
  18. doAssert seq[Table[int, seq[Table[int, string]]]].new() == 5 # Truly complex type test