summaryrefslogtreecommitdiff
path: root/src/test/java/org
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-08-02 10:07:28 +0100
committerMichael Williamson <mike@zwobble.org>2026-08-02 10:17:47 +0100
commit74e48f7b3961bb84b68b9dd795e564735196489c (patch)
treec73a8a337d17f590c9dc9bc2cd0a7e265feff0f7 /src/test/java/org
parent113f53a4268d05618f91eda2fc6c379bb7c23383 (diff)
Introduce SumVariant
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSubtypingTests.java29
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSumDefinitionTests.java18
2 files changed, 37 insertions, 10 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSubtypingTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSubtypingTests.java
index e2b43d0..7080b81 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSubtypingTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSubtypingTests.java
@@ -1,10 +1,7 @@
package org.zwobble.hobgoblin.compiler.typechecker;
import org.junit.jupiter.api.Test;
-import org.zwobble.hobgoblin.compiler.types.NamespaceName;
-import org.zwobble.hobgoblin.compiler.types.SimpleNativeType;
-import org.zwobble.hobgoblin.compiler.types.StructType;
-import org.zwobble.hobgoblin.compiler.types.SumType;
+import org.zwobble.hobgoblin.compiler.types.*;
import java.util.List;
@@ -39,7 +36,14 @@ public class TypeCheckerSubtypingTests {
var variantType2 = new StructType(NamespaceName.of(), "Circle");
var sumType = new SumType(NamespaceName.of(), "Shape");
var typesInfo = TypesInfoInMemory.empty();
- typesInfo.defineSumType(sumType, List.of(variantType1, variantType2), List.of());
+ typesInfo.defineSumType(
+ sumType,
+ List.of(
+ new SumVariant(0, variantType1, variantType1),
+ new SumVariant(1, variantType2, variantType2)
+ ),
+ List.of()
+ );
var isSubtype = isSubtype(variantType1, sumType, typesInfo);
@@ -53,11 +57,22 @@ public class TypeCheckerSubtypingTests {
var variantType1 = new StructType(NamespaceName.of(), "Rectangle");
var variantType2 = new StructType(NamespaceName.of(), "Circle");
var sumType = new SumType(NamespaceName.of(), "Shape");
- typesInfo.defineSumType(sumType, List.of(variantType1, variantType2), List.of());
+ typesInfo.defineSumType(
+ sumType,
+ List.of(
+ new SumVariant(0, variantType1, variantType1),
+ new SumVariant(1, variantType2, variantType2)
+ ),
+ List.of()
+ );
var otherSumType = new SumType(NamespaceName.of(), "Shape3D");
var otherVariantType = new StructType(NamespaceName.of(), "Cube");
- typesInfo.defineSumType(sumType, List.of(otherVariantType), List.of());
+ typesInfo.defineSumType(
+ otherSumType,
+ List.of(new SumVariant(0, otherVariantType, otherVariantType)),
+ List.of()
+ );
var isSubtype = isSubtype(variantType1, otherSumType, typesInfo);
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSumDefinitionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSumDefinitionTests.java
index 5d9897b..96f2e5d 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSumDefinitionTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSumDefinitionTests.java
@@ -82,7 +82,13 @@ public class TypeCheckerSumDefinitionTests {
var typesInfo = globalContext.toTypesInfo();
assertThat(typesInfo.variantOf(rectangleType), isSequence(equalTo(sumType)));
assertThat(typesInfo.variantOf(triangleType), isSequence(equalTo(sumType)));
- assertThat(typesInfo.sumVariants(sumType), isSequence(equalTo(rectangleType), equalTo(triangleType)));
+ assertThat(
+ typesInfo.sumVariants(sumType),
+ isSequence(
+ equalTo(new SumVariant(0, rectangleType, rectangleType)),
+ equalTo(new SumVariant(1, triangleType, triangleType))
+ )
+ );
}
@Test
@@ -133,7 +139,13 @@ public class TypeCheckerSumDefinitionTests {
var typesInfo = globalContext.toTypesInfo();
assertThat(typesInfo.variantOf(rectangleType), isSequence(equalTo(sumType)));
assertThat(typesInfo.variantOf(triangleType), isSequence(equalTo(sumType)));
- assertThat(typesInfo.sumVariants(sumType), isSequence(equalTo(rectangleType), equalTo(triangleType)));
+ assertThat(
+ typesInfo.sumVariants(sumType),
+ isSequence(
+ equalTo(new SumVariant(0, NativeTypes.box(rectangleType), rectangleType)),
+ equalTo(new SumVariant(1, triangleType, triangleType))
+ )
+ );
}
@Test
@@ -309,7 +321,7 @@ public class TypeCheckerSumDefinitionTests {
namespaceContext.declare("Sum", new TypeLevelValueType(sumType), NullSource.INSTANCE);
namespaceContext.defineSumType(
sumType,
- List.of(variantType),
+ List.of(new SumVariant(0, variantType, variantType)),
List.of(new Field("area", int32Type, NullSource.INSTANCE))
);