Skip to content

Commit

Permalink
sema: improve declaration handling for multi-assign statements
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Aug 29, 2024
1 parent 2ee8bdf commit 2b7d38d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/julec/obj/cxx/scope.jule
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion std/jule/sema/scope.jule
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ struct Assign {

// Multi-declarative assignment.
struct MultiAssign {
Decls: []&Var
Left: []&Data // Nil Model:s represents ingored expressions.
Right: ExprModel
}
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 2b7d38d

Please sign in to comment.