summary refs log tree commit diff stats
path: root/tests/misc/t5540.nim
blob: 6a19e70e1e757c0d3c5ded662093b1bde68f449f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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