Skip to content

Commit

Permalink
fix: for statement init declarations (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
shenyih0ng authored Apr 17, 2024
1 parent 3134686 commit d5ce459
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/go-slang/goroutine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,21 @@ const Interpreter: {
)
} else if (form.type === ForFormType.ForClause) {
const { init, cond, post } = form
const initDeclIds = init && init.type === NodeType.VariableDeclaration ? init.left : []
const forCond = {
type: NodeType.ForStatement,
form: { type: ForFormType.ForCondition, expression: cond ?? True },
block: {
type: NodeType.Block,
statements: [
{ ...forBlock, statements: forBlock.statements.concat(ForPostMarker()) },
{
type: NodeType.Block,
statements: [
// eqv to: id = id (copy of init declarations with the current values)
{ type: NodeType.VariableDeclaration, left: initDeclIds, right: initDeclIds },
...forBlock.statements.concat(ForPostMarker())
]
},
post ?? EmptyStmt
]
}
Expand Down

0 comments on commit d5ce459

Please sign in to comment.