aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionDefinitionTests.java16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionDefinitionTests.java b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionDefinitionTests.java
index b44b0f96..352e46b6 100644
--- a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionDefinitionTests.java
+++ b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionDefinitionTests.java
@@ -3,6 +3,7 @@ package org.shedlang.compiler.typechecker;
import org.junit.jupiter.api.Test;
import org.shedlang.compiler.ast.untyped.Untyped;
import org.shedlang.compiler.ast.untyped.UntypedFunctionDefinitionNode;
+import org.shedlang.compiler.typechecker.errors.FunctionSignatureMissingReturnTypeError;
import org.shedlang.compiler.types.Effects;
import org.shedlang.compiler.types.FunctionType;
import org.shedlang.compiler.types.Types;
@@ -11,6 +12,7 @@ import org.shedlang.compiler.util.P;
import java.util.List;
import java.util.Map;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.shedlang.compiler.ast.typed.TypedNodeMatchers.*;
import static org.shedlang.compiler.typechecker.TypeCheckerTesting.typeCheckNamespaceStatement;
import static org.zwobble.precisely.AssertThat.assertThat;
@@ -40,4 +42,18 @@ public class TypeCheckerFunctionDefinitionTests {
.withType(new FunctionType(List.of(), List.of(), Effects.NONE, Types.UNIT))
);
}
+
+ @Test
+ public void whenSignatureIsMissingReturnTypeThenErrorIsThrown() {
+ var untyped = UntypedFunctionDefinitionNode.builder()
+ .withoutReturnType()
+ .build();
+ var context = TypeCheckerContext.EMPTY
+ .enterGlobal(P.map(Map.entry("Unit", Types.metaType(Types.UNIT))));
+
+ assertThrows(
+ FunctionSignatureMissingReturnTypeError.class,
+ () -> typeCheckNamespaceStatement(untyped, context)
+ );
+ }
}