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.java8
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/typechecker/errors/SumVariantMustBeStructError.java18
2 files changed, 24 insertions, 2 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 a40bd92..c2eae29 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java
@@ -286,8 +286,12 @@ public class TypeChecker {
} else {
variantValueType = variantType.value();
}
- // TODO: handle not struct type
- var variant = new SumVariant(variants.size(), variantType.value(), (StructType) variantValueType);
+
+ if (!(variantValueType instanceof StructType variantValueStructType)) {
+ throw new SumVariantMustBeStructError(variantValueType, untypedVariant.source());
+ }
+
+ var variant = new SumVariant(variants.size(), variantType.value(), variantValueStructType);
variants.add(variant);
}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/errors/SumVariantMustBeStructError.java b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/errors/SumVariantMustBeStructError.java
new file mode 100644
index 0000000..78235ae
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/errors/SumVariantMustBeStructError.java
@@ -0,0 +1,18 @@
+package org.zwobble.hobgoblin.compiler.typechecker.errors;
+
+import org.zwobble.hobgoblin.compiler.errors.SourceError;
+import org.zwobble.hobgoblin.compiler.sources.Source;
+import org.zwobble.hobgoblin.compiler.types.Type;
+
+public class SumVariantMustBeStructError extends SourceError {
+ private final Type variantType;
+
+ public SumVariantMustBeStructError(Type variantType, Source source) {
+ super("sum variants must be structs, but was " + variantType.describe(), source);
+ this.variantType = variantType;
+ }
+
+ public Type variantType() {
+ return variantType;
+ }
+}