tgenericdefaultvalue.nim 457 B

123456789101112131415161718192021222324252627
  1. block: # issue #23594
  2. type
  3. Gen[T] = object
  4. a: T = 1.0
  5. Spec32 = Gen[float32]
  6. Spec64 = Gen[float64]
  7. var
  8. a: Spec32
  9. b: Spec64
  10. doAssert sizeof(a) == 4
  11. doAssert sizeof(b) == 8
  12. doAssert a.a is float32
  13. doAssert b.a is float64
  14. block: # issue #21941
  15. func what[T](): T =
  16. 123
  17. type MyObject[T] = object
  18. f: T = what[T]()
  19. var m: MyObject[float] = MyObject[float]()
  20. doAssert m.f is float
  21. doAssert m.f == 123.0