summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java
index c6f8721..408a0b2 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java
@@ -313,6 +313,9 @@ public class TypeChecker {
// TODO: set source appropriately.
throw new SubtypeIsMissingFieldError(sumType, variantType, sumTypeField.name(), NullSource.INSTANCE);
}
+
+ // TODO: set source appropriately.
+ checkIsSubtype(variantTypeField.get().type(), sumTypeField.type(), NullSource.INSTANCE);
}
}
@@ -385,4 +388,18 @@ public class TypeChecker {
return value;
}
+
+ private static void checkIsSubtype(Type subtype, Type supertype, Source source) {
+ if (!isSubtype(subtype, supertype)) {
+ throw new UnexpectedTypeError(
+ new TypeSet.SingleType(supertype),
+ subtype,
+ source
+ );
+ }
+ }
+
+ private static boolean isSubtype(Type subtype, Type supertype) {
+ return subtype.equals(supertype);
+ }
}