Skip to content

Commit 3a3811a

Browse files
committed
VarDecl: Passthrough the return instead of assigning the value to the current symbol
1 parent b1e931e commit 3a3811a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/main/java/org/piccode/ast/VarDecl.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.piccode.piccodescript.TargetEnvironment;
44
import org.piccode.rt.Context;
55
import org.piccode.rt.PiccodeReturnException;
6+
import org.piccode.rt.PiccodeException;
67
import org.piccode.rt.PiccodeValue;
78

89
/**
@@ -34,12 +35,16 @@ public PiccodeValue execute(Integer frame) {
3435
PiccodeValue _value = null;
3536
try {
3637
_value = value.execute(frame);
38+
ctx.dropStackFrame();
39+
ctx.putLocal(name, _value);
40+
return _value;
3741
} catch (PiccodeReturnException ret) {
38-
_value = ret.value;
42+
ctx.dropStackFrame();
43+
throw ret;
44+
} catch (PiccodeException err) {
45+
ctx.dropStackFrame();
46+
throw err;
3947
}
40-
ctx.dropStackFrame();
41-
ctx.putLocal(name, _value);
42-
return _value;
4348
}
4449

4550
@Override

0 commit comments

Comments
 (0)