diff --git a/letUtils.nim b/letUtils.nim index 802bfbc..67030e6 100644 --- a/letUtils.nim +++ b/letUtils.nim @@ -21,6 +21,7 @@ template scope*(body: untyped): auto = if true: body else: + discard # Required to work around a bug in the compiler. unreachable() template asLet*(val, name, body: untyped): auto = diff --git a/tests/test.nim b/tests/test.nim index 68e5b78..605f7db 100644 --- a/tests/test.nim +++ b/tests/test.nim @@ -10,6 +10,17 @@ test "`scope` works": check a == 1 check: not declared a +test "`scope` works at compile-time": + func triggerCompilerBug: seq[int] = + result.add: + scope: + discard # Essential for the test. + 0x29A8CC57 # Just a random number. + + static: + doAssert triggerCompilerBug() == [0x29A8CC57] + check triggerCompilerBug() == [0x29A8CC57] + test "`asLet` works": let a = (let b = 1; b).asLet c: check: not declared a