diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2021-05-23 01:02:04 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-23 01:02:04 -0700 |
commit | 1636c05d138a7a52c5b6cb3cafe6ab84f59f086b (patch) | |
tree | 9887e3312533e46e48853ae190373c14a9c3d0a2 /tests | |
parent | e12597589f2a8cdaabe09e8b2b92ff0fbe3727ef (diff) | |
download | Nim-1636c05d138a7a52c5b6cb3cafe6ab84f59f086b.tar.gz |
close #5540 generic object with generic field evaluated too early (#18062)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/misc/t5540.nim | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/misc/t5540.nim b/tests/misc/t5540.nim new file mode 100644 index 000000000..6a19e70e1 --- /dev/null +++ b/tests/misc/t5540.nim @@ -0,0 +1,45 @@ +# bug #5540; works in 1.2.0 +# fails in 1.0 (Error: cannot generate VM code for) +# fails in 0.18.0 (Error: type mismatch: got <type T>) + +block: + type + Fruit = object + Yellow = object + a: int + template getColor(x: typedesc[Fruit]): typedesc = Yellow + type + Banana[T] = object + b: T + a: getColor(Fruit) + Apple[T] = object + a: T + b: getColor(T) + block: + var x: Banana[int] + doAssert x.b == 0 + doAssert x.a is Yellow + block: + var x: Apple[Fruit] + doAssert x.b is Yellow + +block: + type + Fruit = object + Yellow = object + a: int + + template getColor(x: typedesc[Fruit]): typedesc = Yellow + + type + Banana[T] = object + b: T + a: getColor(Fruit) + + Apple[T] = object + a: T + b: getColor(T) + + var x: Banana[int] + x.b = 13 + x.a.a = 17 |