diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-08-10 10:12:48 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-08-10 10:12:48 +0100 |
| commit | 5d41166750e0f05da436bf30c7a642749f7a71c5 (patch) | |
| tree | 3a300ac4a091adcd7f8e66dee64062065f995030 /src/test/java | |
| parent | eb145887ab57b75299a55c85c753d3b4707105be (diff) | |
Prevent singleton struct from being generic
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java index 1de6cbf..fa913fa 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java @@ -6,11 +6,13 @@ import org.zwobble.hobgoblin.compiler.ast.typed.TypedStructDefinitionNode; import org.zwobble.hobgoblin.compiler.ast.typed.TypedStructFieldDefinitionNode; import org.zwobble.hobgoblin.compiler.ast.typed.TypedTypeLevelExpressionNode; import org.zwobble.hobgoblin.compiler.ast.untyped.*; +import org.zwobble.hobgoblin.compiler.typechecker.errors.SingletonStructCannotHaveTypeParamsError; import org.zwobble.hobgoblin.compiler.types.*; import java.util.List; import java.util.Optional; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.zwobble.hobgoblin.compiler.typechecker.TypeCheckerTesting.typeCheckNamespaceStatement; import static org.zwobble.hobgoblin.compiler.types.TypeMatchers.isField; import static org.zwobble.precisely.AssertThat.assertThat; @@ -48,6 +50,7 @@ public class TypeCheckerStructDefinitionTests { UntypedTypeParamNode.arbitrary().withName("A").build(), UntypedTypeParamNode.arbitrary().withName("B").build() ))) + .withFields(List.of()) .build(); var context = TypeCheckerContextArb.namespaceContext(NamespaceName.of("a", "b")); @@ -130,15 +133,11 @@ public class TypeCheckerStructDefinitionTests { @Test public void singletonStructHasNoFields() { - var int32Type = SimpleNativeType.builtin("Int32"); - var int64Type = SimpleNativeType.builtin("Int64"); var untyped = UntypedStructDefinitionNode.arbitrary() .withName("X") .withFields(Optional.empty()) .build(); var globalContext = TypeCheckerGlobalContext.initial(); - globalContext.addNativeType(int32Type); - globalContext.addNativeType(int64Type); var namespaceName = NamespaceName.of("a", "b"); var namespaceContext = globalContext.enterNamespace(namespaceName); @@ -160,6 +159,23 @@ public class TypeCheckerStructDefinitionTests { } @Test + public void singletonStructCannotHaveTypeParams() { + var untyped = UntypedStructDefinitionNode.arbitrary() + .withName("X") + .withTypeParams(List.of(UntypedTypeParamNode.arbitrary().build())) + .withFields(Optional.empty()) + .build(); + var globalContext = TypeCheckerGlobalContext.initial(); + var namespaceName = NamespaceName.of("a", "b"); + var namespaceContext = globalContext.enterNamespace(namespaceName); + + assertThrows( + SingletonStructCannotHaveTypeParamsError.class, + () -> typeCheckNamespaceStatement(untyped, namespaceContext) + ); + } + + @Test public void whenStructDefinitionHasTypeParamsThenTypeParamsAreBoundWithinStructDefinition() { var untyped = UntypedStructDefinitionNode.arbitrary() .withName("X") |
