diff options
author | LemonBoy <thatlemon@gmail.com> | 2018-08-23 15:17:38 +0200 |
---|---|---|
committer | LemonBoy <thatlemon@gmail.com> | 2018-10-19 22:17:38 +0200 |
commit | 5afcd09cb3d75d4f01427082563966e3f435c9a2 (patch) | |
tree | d1fba8bc6de54aace6bdc5ce44514713c85535b2 /tests/objects/twhen1.nim | |
parent | 7532b37405c9365f3f2935633111f309234297b2 (diff) | |
download | Nim-5afcd09cb3d75d4f01427082563966e3f435c9a2.tar.gz |
Pervasive replacement of nkRecWhen in generic types
Long story short, even if the type contains no reference at all to its generic parameters we still have to walk its AST and evaluate any nkRecWhen nodes that semRecordNodeAux skipped due to the type being a generic one. We also must be careful to modify the type `n` node in place since it may be referenced by the caller as seen in the tillegaltyperecursion test. Moreover we also can't have the nkSym drift away from their original values in order not to break the JS nkObjConstr codegen.
Diffstat (limited to 'tests/objects/twhen1.nim')
-rw-r--r-- | tests/objects/twhen1.nim | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/objects/twhen1.nim b/tests/objects/twhen1.nim new file mode 100644 index 000000000..2301d255a --- /dev/null +++ b/tests/objects/twhen1.nim @@ -0,0 +1,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] |