summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-08-02 13:58:54 +0100
committerMichael Williamson <mike@zwobble.org>2026-08-02 13:58:54 +0100
commit65342425fe891ad54b997d8228d72770d02c2441 (patch)
treefd6d2dde8e6543897dbd80535f689818f6a3a62b /src/test
parent4c2db9bb403c8ffc04eadb6ab262d5137f216000 (diff)
Check sum and variant are from the same namespace
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSumDefinitionTests.java26
1 files changed, 26 insertions, 0 deletions
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 1120bbe..be9790a 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSumDefinitionTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSumDefinitionTests.java
@@ -9,6 +9,7 @@ import org.zwobble.hobgoblin.compiler.ast.untyped.*;
import org.zwobble.hobgoblin.compiler.builtins.NativeTypes;
import org.zwobble.hobgoblin.compiler.sources.NullSource;
import org.zwobble.hobgoblin.compiler.typechecker.errors.SubtypeIsMissingFieldError;
+import org.zwobble.hobgoblin.compiler.typechecker.errors.SumVariantMustBeInSameNamespaceError;
import org.zwobble.hobgoblin.compiler.typechecker.errors.SumVariantMustBeStructError;
import org.zwobble.hobgoblin.compiler.typechecker.errors.UnexpectedTypeError;
import org.zwobble.hobgoblin.compiler.types.*;
@@ -174,6 +175,31 @@ public class TypeCheckerSumDefinitionTests {
}
@Test
+ public void variantMustBeInSameNamespace() {
+ var untyped = UntypedSumDefinitionNode.arbitrary()
+ .withName("X")
+ .withVariants(List.of(
+ UntypedSumVariantDefinitionNode.arbitrary()
+ .withType(UntypedArb.typeLevelReference("Variant"))
+ .build()
+ ))
+ .build();
+ var variantType = new StructType(NamespaceName.of("other"), "Variant");
+ var globalContext = TypeCheckerGlobalContext.initial();
+ globalContext.addNativeTypeConstructor(NativeTypes.BOX);
+ var namespaceContext = globalContext
+ .enterNamespace(NamespaceName.of("a", "b"));
+ namespaceContext.declare("Variant", new TypeLevelValueType(variantType), NullSource.INSTANCE);
+
+ var error = assertThrows(
+ SumVariantMustBeInSameNamespaceError.class,
+ () -> typeCheckNamespaceStatement(untyped, namespaceContext)
+ );
+
+ assertThat(error.namespaceName(), equalTo(NamespaceName.of("other")));
+ }
+
+ @Test
public void fieldsAreTypeChecked() {
var int32Type = SimpleNativeType.builtin("Int32");
var int64Type = SimpleNativeType.builtin("Int64");