diff options
author | cooldome <cdome@bk.ru> | 2018-10-18 19:21:25 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-10-18 20:21:25 +0200 |
commit | eaca5be9d6e205e8aa7055306122a6c053ef35a6 (patch) | |
tree | 784c5f2726a94b656e3f85ab231c4dfc377cc167 /tests | |
parent | 15dbd973dec848f1c429fe7043e53254a501812b (diff) | |
download | Nim-eaca5be9d6e205e8aa7055306122a6c053ef35a6.tar.gz |
Change the order of compilation passes, transformation is made lazy at code gen (#8489)
* Ast no transformation * Add getImplNoTransform to the macros module * progress on delaying transf * Fix methods tranformation * Fix lazy lambdalifting * fix create thread wrapper * transform for lambda lifting * improve getImplTransformed * Fix destructor tests * try to fix nimprof for linux
Diffstat (limited to 'tests')
-rw-r--r-- | tests/destructor/tprevent_assign2.nim | 21 | ||||
-rw-r--r-- | tests/destructor/tprevent_assign3.nim | 53 | ||||
-rw-r--r-- | tests/macros/tmacrostmt.nim | 2 |
3 files changed, 58 insertions, 18 deletions
diff --git a/tests/destructor/tprevent_assign2.nim b/tests/destructor/tprevent_assign2.nim index feb635964..0e4481710 100644 --- a/tests/destructor/tprevent_assign2.nim +++ b/tests/destructor/tprevent_assign2.nim @@ -1,12 +1,7 @@ discard """ errormsg: "'=' is not available for type <Foo>; requires a copy because it's not the last read of 'otherTree'" - - cmd: "nim check --hint[Performance]:off $file" - nimout: ''' -tprevent_assign2.nim(53, 31) Error: '=' is not available for type <Foo>; requires a copy because it's not the last read of 'otherTree'; another read is done here: tprevent_assign2.nim(52, 13) -tprevent_assign2.nim(55, 31) Error: '=' is not available for type <Foo>; requires a copy because it's not the last read of 'otherTree'; another read is done here: tprevent_assign2.nim(52, 13) -tprevent_assign2.nim(66, 29) Error: '=' is not available for type <Foo>; requires a copy because it's not the last read of 'otherTree'; another read is done here: tprevent_assign2.nim(68, 9) -''' + file: "tprevent_assign2.nim" + line: 48 """ type @@ -56,13 +51,5 @@ proc preventThis() = else: discard -proc preventThis2() = - var otherTree: Foo - try: - try: - otherTree = createTree(44) - echo otherTree - finally: - take2(createTree(34), otherTree) - finally: - echo otherTree +allowThis() +preventThis() diff --git a/tests/destructor/tprevent_assign3.nim b/tests/destructor/tprevent_assign3.nim new file mode 100644 index 000000000..a8a35ea5e --- /dev/null +++ b/tests/destructor/tprevent_assign3.nim @@ -0,0 +1,53 @@ +discard """ + errormsg: "'=' is not available for type <Foo>; requires a copy because it's not the last read of 'otherTree'" + file: "tprevent_assign3.nim" + line: 46 +""" + +type + Foo = object + x: int + +proc `=destroy`(f: var Foo) = f.x = 0 +proc `=`(a: var Foo; b: Foo) {.error.} # = a.x = b.x +proc `=sink`(a: var Foo; b: Foo) = a.x = b.x + +proc createTree(x: int): Foo = + Foo(x: x) + +proc take2(a, b: sink Foo) = + echo a.x, " ", b.x + +proc allowThis() = + var otherTree: Foo + try: + for i in 0..3: + while true: + #if i == 0: + otherTree = createTree(44) + case i + of 0: + echo otherTree + take2(createTree(34), otherTree) + of 1: + take2(createTree(34), otherTree) + else: + discard + finally: + discard + +proc preventThis2() = + var otherTree: Foo + try: + try: + otherTree = createTree(44) + echo otherTree + finally: + take2(createTree(34), otherTree) + finally: + echo otherTree + +allowThis() +preventThis2() + + diff --git a/tests/macros/tmacrostmt.nim b/tests/macros/tmacrostmt.nim index c1f26e626..e4b8e2fe4 100644 --- a/tests/macros/tmacrostmt.nim +++ b/tests/macros/tmacrostmt.nim @@ -94,7 +94,7 @@ proc fn3(x, y: int): bool = static: let fn1s = "proc fn1(x, y: int): int =\n result = 2 * (x + y)\n" - let fn2s = "proc fn2(x, y: float): float =\n result = (y + 2.0 * x) / (x - y)\n" + let fn2s = "proc fn2(x, y: float): float =\n result = (y + 2 * x) / (x - y)\n" let fn3s = "proc fn3(x, y: int): bool =\n result = ((x and 3) div 4 or x mod (y xor -1)) == 0 or not contains([1, 2], y)\n" doAssert fn1.repr_to_string == fn1s doAssert fn2.repr_to_string == fn2s |