Skip to content

Commit ddd88dd

Browse files
committed
Property fix
1 parent e1851f5 commit ddd88dd

4 files changed

Lines changed: 29 additions & 4 deletions

File tree

rulescript/RuleScriptInterp.hx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ class RuleScriptInterp extends hscript.Interp
176176
if (e != null)
177177
prop._lazyValue = () -> this.expr(e);
178178
return null;
179+
case EIdent(id):
180+
var l = locals.get(id);
181+
if (l != null)
182+
return getScriptProp(l.r);
183+
return resolve(id);
179184
case EFor(key, it, e, value):
180185
if (value == null)
181186
forLoop(key, it, e);

rulescript/RuleScriptProperty.hx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class RuleScriptProperty
2020

2121
@:isVar public var value(get, set):Dynamic;
2222

23+
var _inProperty:Bool = false;
24+
2325
public function new(?get:Property = DEFAULT, ?set:Property = DEFAULT)
2426
{
2527
this._get = get;
@@ -28,30 +30,48 @@ class RuleScriptProperty
2830

2931
function get_value():Dynamic
3032
{
33+
if (_inProperty)
34+
return this.value;
35+
3136
initLazy();
3237

33-
return switch (_get)
38+
_inProperty = true;
39+
40+
var v:Dynamic = switch (_get)
3441
{
3542
case DEFAULT | NULL: this.value;
3643
case GET(f): f();
3744
case SET(f): throw 'Custom property accessor is no longer supported, please use `get`';
3845
case DYNAMIC(f): f();
3946
case NEVER: throw 'This expression cannot be accessed for reading';
4047
}
48+
49+
_inProperty = false;
50+
51+
return v;
4152
}
4253

4354
function set_value(v:Dynamic):Dynamic
4455
{
56+
if (_inProperty)
57+
return this.value = v;
58+
4559
initLazy();
4660

47-
return switch (_set)
61+
_inProperty = true;
62+
63+
var v:Dynamic = switch (_set)
4864
{
4965
case DEFAULT | NULL: this.value = v;
5066
case GET(f): throw 'Custom property accessor is no longer supported, please use `set`';
5167
case SET(f): f(v);
5268
case DYNAMIC(f): f(v);
5369
case NEVER: throw 'This expression cannot be accessed for writing';
5470
}
71+
72+
_inProperty = false;
73+
74+
return v;
5575
}
5676

5777
inline function initLazy()

test/scripts/haxe/PropertyTest.rhx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ function set_a(v:String):String
1616

1717
a = 'Hello World';
1818

19-
return _a;
19+
return a;

test/src/Main.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ class Main
283283

284284
// Custom constructor can't have extra args
285285

286-
new ScriptedClassTestStrict('ScriptedClass', 'Script');
286+
new ScriptedClassTestStrict('ScriptedClassStrict', 'Script');
287287

288288
var srcClass = new SrcClassTest<Hello<Int>, Int>('Src'),
289289
scriptClass = new ScriptedClassTest('ScriptedClass', [4, 'Script']);

0 commit comments

Comments
 (0)