From 388d0ffe5fd2915eafefb2b5e0ffaae9c88e7aba Mon Sep 17 00:00:00 2001 From: nico-bb <64324649+nico-bb@users.noreply.github.com> Date: Fri, 29 Jul 2022 10:26:43 +0200 Subject: Fix ternary when expression + added the test to snapshot --- src/odin/printer/visit.odin | 4 ++-- tools/odinfmt/tests/.snapshots/assignments.odin | 4 ++++ tools/odinfmt/tests/assignments.odin | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index 04d1ada..a76ab47 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -1045,9 +1045,9 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, called_from: Expr_Called_Type = document = cons_with_opl(document, group(visit_expr(p, v.y))) } case ^Ternary_When_Expr: - document = visit_expr(p, v.cond) + document = visit_expr(p, v.x) document = cons_with_nopl(document, text_token(p, v.op1)) - document = cons_with_nopl(document, visit_expr(p, v.x)) + document = cons_with_nopl(document, visit_expr(p, v.cond)) document = cons_with_nopl(document, text_token(p, v.op2)) document = cons_with_nopl(document, visit_expr(p, v.y)) case ^Or_Else_Expr: diff --git a/tools/odinfmt/tests/.snapshots/assignments.odin b/tools/odinfmt/tests/.snapshots/assignments.odin index 7b09796..338e33b 100644 --- a/tools/odinfmt/tests/.snapshots/assignments.odin +++ b/tools/odinfmt/tests/.snapshots/assignments.odin @@ -11,3 +11,7 @@ assignments :: proc() { &big.Int{} } + +ternary_when_assignment :: proc() { + a := WGL_CONTEXT_FLAGS_ARB when ODIN_DEBUG else 0 +} diff --git a/tools/odinfmt/tests/assignments.odin b/tools/odinfmt/tests/assignments.odin index c90b04e..9a92866 100644 --- a/tools/odinfmt/tests/assignments.odin +++ b/tools/odinfmt/tests/assignments.odin @@ -4,3 +4,7 @@ assignments :: proc() { a, b, c, d, e, f, res := &big.Int{}, &big.Int{}, &big.Int{}, &big.Int{}, &big.Int{}, &big.Int{}, &big.Int{} } + +ternary_when_assignment :: proc() { + a := WGL_CONTEXT_FLAGS_ARB when ODIN_DEBUG else 0 +} -- cgit v1.2.3