From 70f6a2055dd4f267876a73423877cb0a7c85cc70 Mon Sep 17 00:00:00 2001 From: Shen Yi Hong Date: Wed, 17 Apr 2024 00:02:30 +0800 Subject: [PATCH] fix: preceding simple statement in `IfStmt` should have its own block --- src/go-slang/goroutine.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/go-slang/goroutine.ts b/src/go-slang/goroutine.ts index c2810aa33..376bfa7dc 100644 --- a/src/go-slang/goroutine.ts +++ b/src/go-slang/goroutine.ts @@ -184,7 +184,14 @@ const Interpreter: { IfStatement: ({ stmt, cond, cons, alt }: IfStatement, { C, H }) => { const branchOp: BranchOp = { type: CommandType.BranchOp, cons, alt } - stmt ? C.pushR(...H.allocM([stmt, cond, branchOp])) : C.pushR(...H.allocM([cond, branchOp])) + stmt + ? C.push( + H.alloc({ + type: NodeType.Block, + statements: [stmt, { type: NodeType.IfStatement, cond, cons, alt }] + }) + ) + : C.pushR(...H.allocM([cond, branchOp])) }, ForStatement: (inst: ForStatement, { C, H }) => {