summaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/zwobble')
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerConstructedTypeTests.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerConstructedTypeTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerConstructedTypeTests.java
index c0a7f93..4f409d2 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerConstructedTypeTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerConstructedTypeTests.java
@@ -3,6 +3,7 @@ package org.zwobble.hobgoblin.compiler.typechecker;
import org.junit.jupiter.api.Test;
import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedArb;
import org.zwobble.hobgoblin.compiler.sources.NullSource;
+import org.zwobble.hobgoblin.compiler.typechecker.errors.UnexpectedTypeError;
import org.zwobble.hobgoblin.compiler.typechecker.errors.WrongNumberOfTypeLevelArgsError;
import org.zwobble.hobgoblin.compiler.types.*;
@@ -15,6 +16,27 @@ import static org.zwobble.precisely.Matchers.equalTo;
public class TypeCheckerConstructedTypeTests {
@Test
+ public void whenReceiverIsNotTypeConstructorThenErrorIsThrown() {
+ var untyped = UntypedArb.constructedType(
+ UntypedArb.typeLevelReference("List"),
+ List.of(UntypedArb.typeLevelReference("Int32"))
+ );
+ var context = TypeCheckerContextArb.namespaceContext();
+ var listType = SimpleNativeType.builtin("List");
+ context.declare("List", new TypeLevelValueType(listType), NullSource.INSTANCE);
+ var int32Type = SimpleNativeType.builtin("Int32");
+ context.declare("Int32", new TypeLevelValueType(int32Type), NullSource.INSTANCE);
+
+ var error = assertThrows(
+ UnexpectedTypeError.class,
+ () -> TypeChecker.typeCheckTypeLevelExpression(untyped, context)
+ );
+
+ assertThat(error.expected(), equalTo(new TypeSet.TypeConstructor()));
+ assertThat(error.actual(), equalTo(new TypeLevelValueType(listType)));
+ }
+
+ @Test
public void whenArgsMatchParamsThenCanConstructTypeFromTypeConstructor() {
var untyped = UntypedArb.constructedType(
UntypedArb.typeLevelReference("List"),