forked from nim-lang/Nim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
close nim-lang#5540 generic object with generic field evaluated too e…
…arly
- Loading branch information
1 parent
e125975
commit 010b554
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) # 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 |