From 2a1d8a2703c5f2bd927e1d942012439ac39a40fd Mon Sep 17 00:00:00 2001 From: DanielGavin Date: Thu, 21 Sep 2023 19:09:25 +0200 Subject: [PATCH] Fix issues with assignments not formatting like value decls --- src/odin/printer/visit.odin | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index 6e9a7f77..386a390e 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -488,6 +488,24 @@ is_value_decl_statement_ending_with_call :: proc(stmt: ^ast.Stmt) -> bool { return false } +@(private) +is_assign_statement_ending_with_call :: proc(stmt: ^ast.Stmt) -> bool { + if assign_stmt, ok := stmt.derived.(^ast.Assign_Stmt); ok { + if len(assign_stmt.rhs) == 0 { + return false + } + + #partial switch v in + assign_stmt.rhs[len(assign_stmt.rhs) - 1].derived { + case ^ast.Call_Expr, ^ast.Selector_Call_Expr: + fmt.println("TRUE") + return true + } + } + + return false +} + @(private) is_value_expression_call :: proc(expr: ^ast.Expr) -> bool { #partial switch v in expr.derived { @@ -1041,6 +1059,7 @@ visit_stmt :: proc( if v.init != nil && is_value_decl_statement_ending_with_call(v.init) || + v.init != nil && is_assign_statement_ending_with_call(v.init) || v.cond != nil && v.init == nil && is_value_expression_call(v.cond) { document = cons( document,