Skip to content

Commit

Permalink
Work around a bug in the compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
SirNickolas committed Mar 6, 2023
1 parent 8a46614 commit d5693c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions letUtils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
11 changes: 11 additions & 0 deletions tests/test.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d5693c8

Please sign in to comment.