Skip to content

Commit e217e3b

Browse files
committed
Возможность изменения полей в классах через ссылку на экземпляр
1 parent b82596c commit e217e3b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/main/java/com/annimon/ownlang/lib/ClassInstanceValue.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ public Value access(Value value) {
4343
return thisMap.get(value);
4444
}
4545

46+
public void set(Value key, Value value) {
47+
final Value v = thisMap.get(key);
48+
if (v == null) {
49+
throw new RuntimeException("Unable to add new field "
50+
+ key.asString() + " to class " + className);
51+
}
52+
thisMap.set(key, value);
53+
}
54+
4655
@Override
4756
public Object raw() {
4857
return null;

src/main/java/com/annimon/ownlang/parser/ast/ContainerAccessExpression.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public Value set(Value value) {
7373
((MapValue) container).set(lastIndex, value);
7474
return value;
7575

76+
case Types.CLASS:
77+
((ClassInstanceValue) container).set(lastIndex, value);
78+
return value;
79+
7680
default:
7781
throw new TypeException("Array or map expected. Got " + container.type());
7882
}

0 commit comments

Comments
 (0)