summary refs log tree commit diff stats
path: root/tests/objects/twhen1.nim
blob: 2301d255a805f5b9f46c0175febc79b2a54e7a6e (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
46
47
48
49
50
51
const Z = 0

type
  Foo[T] = object
   when true:
     u: int
   else:
     v: int
  Foo1[T] = object
   when T is int:
     x: T
   elif true:
     z: char
  Foo2[x:static[int]] = object
    when (x and 1) == 1:
      x: array[x+1,int]
    else:
      x: array[x,int]

  Foo3 = Foo2[128]

  # #8417
  Foo4[A: static[int]] = object
    when Z == 0:
      discard
    else:
      discard

block:
  var x: Foo[int] = Foo[int](u: 42)
  doAssert x.u == 42

# Don't evaluate `when` branches before the type is instantiated
block:
  var x: Foo1[bool] = Foo1[bool](z: 'o')
  doAssert x.z == 'o'

block:
  var x: Foo2[3]
  doAssert x.x.len == 4

block:
  var x: Foo2[4]
  doAssert x.x.len == 4

block:
  var x: Foo3
  doAssert x.x.len == 128

block:
  var x: Foo4[0]