Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

close #5540 generic object with generic field evaluated too early #18062

Merged
merged 2 commits into from
May 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions tests/misc/t5540.nim
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)

Apple[T] = object
a: T
b: getColor(T)

var x: Banana[int]
x.b = 13
x.a.a = 17