diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2024-02-01 23:51:07 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-01 16:51:07 +0100 |
commit | 7d9721007c8c82804450bd32bbf3bbaf806a52f2 (patch) | |
tree | 87d385878e2fb5a4b78d2b3390b1289a3d9874f5 /tests/arc/tarc_macro.nim | |
parent | 519d976f6241023b05b06188e6d96245d0a6a2fe (diff) | |
download | Nim-7d9721007c8c82804450bd32bbf3bbaf806a52f2.tar.gz |
fixes regression #22909; don't optimize result init if statements can raise which corrupts the compiler (#23271)
fixes #22909 required by https://github.com/nim-lang/Nim/pull/23267 ```nim proc foo: string = assert false result = "" ``` In the function `foo`, `assert false` raises an exception, which can cause `result` to be uninitialized if the default result initialization is optimized out
Diffstat (limited to 'tests/arc/tarc_macro.nim')
-rw-r--r-- | tests/arc/tarc_macro.nim | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/tests/arc/tarc_macro.nim b/tests/arc/tarc_macro.nim index ea7d279fd..33ade1da4 100644 --- a/tests/arc/tarc_macro.nim +++ b/tests/arc/tarc_macro.nim @@ -43,4 +43,15 @@ macro bar2() = doAssert &%&%y == 1 # unary operator => need to escape doAssert y &% y == 2 # binary operator => no need to escape doAssert y == 3 -bar2() \ No newline at end of file +bar2() + +block: + macro foo(a: openArray[string] = []): string = + echo a # Segfault doesn't happen if this is removed + newLit "" + + proc bar(a: static[openArray[string]] = []) = + const tmp = foo(a) + + # bug #22909 + doAssert not compiles(bar()) |