From 092c34d8a805f82f7db55bde1bf0d89ff429c0fa Mon Sep 17 00:00:00 2001 From: JalonSolov Date: Mon, 26 Aug 2024 13:38:30 -0400 Subject: [PATCH] fix underscore as var placeholder (#127) --- assign_stmt.v | 25 +++++++++++++------ .../var_underscore/var_underscore.go | 0 .../var_underscore/var_underscore.vv | 0 3 files changed, 17 insertions(+), 8 deletions(-) rename {untested => tests}/var_underscore/var_underscore.go (100%) rename {untested => tests}/var_underscore/var_underscore.vv (100%) diff --git a/assign_stmt.v b/assign_stmt.v index 69c44c4..b3b72d6 100644 --- a/assign_stmt.v +++ b/assign_stmt.v @@ -1,12 +1,21 @@ fn (mut app App) assign_stmt(assign AssignStmt, no_mut bool) { // app.genln('//assign_stmt') - if !no_mut { - if assign.tok == ':=' { - app.gen('mut ') + for i, lhs_expr in assign.lhs { + if i == 0 { + match lhs_expr { + Ident { + if lhs_expr.name != '_' { + if !no_mut { + if assign.tok == ':=' { + app.gen('mut ') + } + } + } + } + else {} + } } - } - for i, expr in assign.lhs { - app.expr(expr) + app.expr(lhs_expr) if i < assign.lhs.len - 1 { app.gen(', ') } @@ -17,8 +26,8 @@ fn (mut app App) assign_stmt(assign AssignStmt, no_mut bool) { } // app.gen(assign.tok) - for expr in assign.rhs { - app.expr(expr) + for rhs_expr in assign.rhs { + app.expr(rhs_expr) } app.genln('') } diff --git a/untested/var_underscore/var_underscore.go b/tests/var_underscore/var_underscore.go similarity index 100% rename from untested/var_underscore/var_underscore.go rename to tests/var_underscore/var_underscore.go diff --git a/untested/var_underscore/var_underscore.vv b/tests/var_underscore/var_underscore.vv similarity index 100% rename from untested/var_underscore/var_underscore.vv rename to tests/var_underscore/var_underscore.vv