From 2b7d38d9d83dd7f61ec418eb9ab96b466461e6c9 Mon Sep 17 00:00:00 2001 From: mertcandav Date: Thu, 29 Aug 2024 10:01:47 +0300 Subject: [PATCH] sema: improve declaration handling for multi-assign statements --- src/julec/obj/cxx/scope.jule | 8 ++++++++ std/jule/sema/scope.jule | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/julec/obj/cxx/scope.jule b/src/julec/obj/cxx/scope.jule index de64d158e..ec05d1d48 100644 --- a/src/julec/obj/cxx/scope.jule +++ b/src/julec/obj/cxx/scope.jule @@ -603,6 +603,14 @@ impl scopeCoder { } fn multiAssign(mut &self, mut a: &MultiAssign) { + // Write declarations without no initialization. + // It will initialize with assignments. + for (_, mut d) in a.Decls { + self.oc.varInitExpr(d, nil) + self.oc.write("\n") + self.oc.indent() + } + // Special cases. match type a.Right { | &IndexingExprModel: // Map lookup. diff --git a/std/jule/sema/scope.jule b/std/jule/sema/scope.jule index 0482ad878..b39236057 100644 --- a/std/jule/sema/scope.jule +++ b/std/jule/sema/scope.jule @@ -371,6 +371,7 @@ struct Assign { // Multi-declarative assignment. struct MultiAssign { + Decls: []&Var Left: []&Data // Nil Model:s represents ingored expressions. Right: ExprModel } @@ -1432,8 +1433,8 @@ impl scopeChecker { Kind: v.Kind.Kind, Model: v, }) + st.Decls = append(st.Decls, v) self.table.Vars = append(self.table.Vars, v) - self.scope.Stmts = append(self.scope.Stmts, v) ret }