aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/couscous/interpreter/values/InterpreterFields.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/zwobble/couscous/interpreter/values/InterpreterFields.java')
-rw-r--r--src/main/java/org/zwobble/couscous/interpreter/values/InterpreterFields.java12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/main/java/org/zwobble/couscous/interpreter/values/InterpreterFields.java b/src/main/java/org/zwobble/couscous/interpreter/values/InterpreterFields.java
index 1661ee7..50ed24f 100644
--- a/src/main/java/org/zwobble/couscous/interpreter/values/InterpreterFields.java
+++ b/src/main/java/org/zwobble/couscous/interpreter/values/InterpreterFields.java
@@ -4,24 +4,25 @@ import org.zwobble.couscous.ast.FieldDeclarationNode;
import org.zwobble.couscous.interpreter.InterpreterTypes;
import org.zwobble.couscous.interpreter.errors.NoSuchField;
import org.zwobble.couscous.interpreter.errors.UnboundField;
+import org.zwobble.couscous.interpreter.types.InterpreterType;
import java.util.HashMap;
import java.util.Map;
public class InterpreterFields {
- public static InterpreterFields forClass(ConcreteType type) {
+ public static InterpreterFields forClass(InterpreterType type) {
return new InterpreterFields(true, type);
}
- public static InterpreterFields forInstanceOf(ConcreteType type) {
+ public static InterpreterFields forInstanceOf(InterpreterType type) {
return new InterpreterFields(false, type);
}
private final boolean isStatic;
- private final ConcreteType type;
+ private final InterpreterType type;
private final Map<String, InterpreterValue> fields;
- private InterpreterFields(boolean isStatic, ConcreteType type) {
+ private InterpreterFields(boolean isStatic, InterpreterType type) {
this.isStatic = isStatic;
this.type = type;
this.fields = new HashMap<>();
@@ -43,7 +44,8 @@ public class InterpreterFields {
}
private FieldDeclarationNode getFieldDefinition(String fieldName) {
- return type.getField(isStatic, fieldName)
+ return type.getField(fieldName)
+ .filter(field -> field.isStatic() == isStatic)
.orElseThrow(() -> new NoSuchField(fieldName));
}
}