diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-06-26 11:39:51 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-06-26 11:39:51 +0100 |
| commit | 45022f09c44fbbd1683cac279ccf53f9ea650446 (patch) | |
| tree | c22fb5a8ab4a16d47b76d51daca4d6c3c4e630f7 /src/main/java/org | |
| parent | 09bbd799f6c12f75af13f24e82f907d6770132e8 (diff) | |
Check variant field types
Diffstat (limited to 'src/main/java/org')
| -rw-r--r-- | src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java | 17 |
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); + } } |
