From 010b5544d2c585b4f9af1aed51b81c07d3ebc6bd Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Sat, 22 May 2021 23:24:14 -0700 Subject: [PATCH 1/2] close #5540 generic object with generic field evaluated too early --- tests/misc/t5540.nim | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/misc/t5540.nim diff --git a/tests/misc/t5540.nim b/tests/misc/t5540.nim new file mode 100644 index 0000000000000..fe9937b8c0501 --- /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 ) + +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) # this one works + + Apple[T] = object + a: T + b: getColor(T) # this one failed to compile + + var x: Banana[int] + x.b = 13 + x.a.a = 17 From 8ea062a4637877651114f361b70a9c018eef2f6e Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Sun, 23 May 2021 01:01:07 -0700 Subject: [PATCH 2/2] address comment --- tests/misc/t5540.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/misc/t5540.nim b/tests/misc/t5540.nim index fe9937b8c0501..6a19e70e1e757 100644 --- a/tests/misc/t5540.nim +++ b/tests/misc/t5540.nim @@ -34,11 +34,11 @@ block: type Banana[T] = object b: T - a: getColor(Fruit) # this one works + a: getColor(Fruit) Apple[T] = object a: T - b: getColor(T) # this one failed to compile + b: getColor(T) var x: Banana[int] x.b = 13