fixes #24850; macro-generated if/else and when/else statements have m… (#24852)

…ismatched indentation with repr

fixes #24850
This commit is contained in:
ringabout
2025-04-08 23:54:31 +08:00
committed by GitHub
parent a625fab098
commit 29a2e25d1e
4 changed files with 62 additions and 28 deletions

View File

@@ -326,3 +326,27 @@ do:
static: main()
main()
import std/macros
# bug #24850
macro a() =
let
y = quote do: discard
b = nnkIfStmt.newTree(
nnkElifExpr.newTree(ident "true", y), nnkElseExpr.newTree(y))
d = nnkWhenStmt.newTree(
nnkElifExpr.newTree(ident "true", y), nnkElseExpr.newTree(y))
doAssert repr(b) == """
if true:
discard
else:
discard"""
doAssert repr(d) == """
when true:
discard
else:
discard"""
a()