timplicit_and_explicit.nim 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. block: # basic test
  2. proc doStuff[T](a: SomeInteger): T = discard
  3. proc doStuff[T;Y](a: SomeInteger, b: Y): Y = discard
  4. assert typeof(doStuff[int](100)) is int
  5. assert typeof(doStuff[int](100, 1.0)) is float
  6. assert typeof(doStuff[int](100, "Hello")) is string
  7. proc t[T](x: T; z: int | float): seq[T] = result.add(x & $z)
  8. assert t[string]("Hallo", 2.0) == @["Hallo" & $2.0]
  9. proc t2[T](z: int | float): seq[T] = result.add($z)
  10. assert t2[string](2.0) == @[$2.0]
  11. block: # template test
  12. template someThing[T;Y](a: SomeFloat, b: SomeOrdinal): (T, Y) = (a, b)
  13. assert typeof(someThing[float64, int](1.0, 100)) is (float64, int)
  14. block: # static test
  15. proc t[T](s: static bool) = discard
  16. proc t2[T](s: static string) = discard
  17. t[string](true)
  18. t2[int]("hello")
  19. t2[string]("world")
  20. t2[float]("test222222")
  21. block: #11152
  22. proc f[T](X: typedesc) = discard
  23. f[int](string)
  24. block: #15622
  25. proc test1[T](a: T, b: static[string] = "") = discard
  26. test1[int64](123)
  27. proc test2[T](a: T, b: static[string] = "") = discard
  28. test2[int64, static[string]](123)
  29. block: #4688
  30. proc convertTo[T](v: int or float): T = (T)(v)
  31. discard convertTo[float](1)
  32. block: #4164
  33. proc printStr[T](s: static[string]): T = discard
  34. discard printStr[int]("hello static")