Skip to content

Commit 40d90a1

Browse files
authored
finals but polymod
1 parent 0fbdf27 commit 40d90a1

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

polymod/hscript/_internal/PolymodAbstractScriptClass.hx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ abstract PolymodAbstractScriptClass(PolymodScriptClass) from PolymodScriptClass
117117
case _:
118118
if (this.findVar(name) != null)
119119
{
120+
var isFinal = this.findVar(name).isfinal;
121+
if (isFinal && this._interp.variables.exists(name)) // The variable already exists and has a set value.
122+
{
123+
throw "Invalid access to field " + name;
124+
return null;
125+
}
120126
this._interp.variables.set(name, value);
121127
return value;
122128
}

polymod/hscript/_internal/PolymodInterpEx.hx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ class PolymodInterpEx extends Interp
231231
var result = (e == null) ? null : expr(e);
232232
locals.set(n, {r: result});
233233
return null;
234+
case EFinal(n, _, e): // Fix to ensure local variables are committed properly.
235+
declared.push({n: n, old: locals.get(n)});
236+
var result = (e == null) ? null : expr(e);
237+
locals.set(n, {r: result, isfinal: true});
238+
return null;
234239
case EFunction(params, fexpr, name, _): // Fix to ensure callback functions catch thrown errors.
235240
var capturedLocals = duplicate(locals);
236241
var me = this;

0 commit comments

Comments
 (0)