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.java22
1 files changed, 20 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 84cb6aa..c713c70 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java
@@ -97,14 +97,32 @@ public class TypeChecker {
UntypedSumDefinitionNode untyped,
TypeCheckerNamespaceContext context
) {
- throw new UnsupportedOperationException("TODO");
+ var sumType = new SumType(context.namespaceName(), untyped.name());
+ // TODO: tidy up declare vs define
+ context.declare(untyped.name());
+ context.define(untyped.name(), new TypeLevelValueType(sumType));
}
private static TypedNamespaceStatementNode defineSumDefinition(
UntypedSumDefinitionNode untyped,
TypeCheckerNamespaceContext context
) {
- throw new UnsupportedOperationException("TODO");
+ var sumType = (SumType) lookupMetaType(untyped.name(), untyped.source(), context);
+
+ var typedVariants = new ArrayList<TypedSumVariantDefinitionNode>();
+ for (var untypedVariant : untyped.variants()) {
+ var typedVariant = new TypedSumVariantDefinitionNode(
+ typeCheckMetaType(untypedVariant.type(), context),
+ untyped.source()
+ );
+ typedVariants.add(typedVariant);
+ }
+
+ return new TypedSumDefinitionNode(
+ sumType,
+ typedVariants,
+ untyped.source()
+ );
}
private static TypedTypeLevelExpressionNode<Type> typeCheckMetaType(