aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-06-10 11:17:03 +0100
committerMichael Williamson <mike@zwobble.org>2023-06-10 11:17:14 +0100
commit646c5b9673ffbbc691db246ca8a253cb3e6ea8a1 (patch)
treec8e9cab7e3c9893994f8c7bce845bf14f66b6e37 /src/test/java
parent482c93fe786d63dd8263bde262acc76467021169 (diff)
Check positional arg type matches param type
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/typechecker/TypeCheckerCallTests.java26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerCallTests.java b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerCallTests.java
index aa7e2bce..fb645d67 100644
--- a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerCallTests.java
+++ b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerCallTests.java
@@ -2,6 +2,7 @@ package org.shedlang.compiler.typechecker;
import org.junit.jupiter.api.Test;
import org.shedlang.compiler.ast.untyped.Untyped;
+import org.shedlang.compiler.typechecker.typesets.TypeSets;
import org.shedlang.compiler.types.FunctionType;
import org.shedlang.compiler.types.Types;
import org.shedlang.compiler.util.P;
@@ -9,8 +10,10 @@ 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.zwobble.precisely.AssertThat.assertThat;
+import static org.zwobble.precisely.Matchers.equalTo;
import static org.zwobble.precisely.Matchers.isSequence;
public class TypeCheckerCallTests {
@@ -94,4 +97,27 @@ public class TypeCheckerCallTests {
)))
);
}
+
+ @Test
+ public void whenPositionalArgHasWrongTypeThenErrorIsThrown() {
+ var untyped = Untyped.call(
+ Untyped.reference("f"),
+ List.of(
+ Untyped.stringLiteral("hello")
+ )
+ );
+ var functionType = FunctionType.builder()
+ .addPositionalParam(Types.INT)
+ .build();
+ var context = TypeCheckerContext.EMPTY
+ .enter(P.map(Map.entry("f", functionType)));
+
+ var error = assertThrows(
+ UnexpectedTypeError.class,
+ () -> TypeChecker.typeCheckExpression(untyped, context)
+ );
+
+ assertThat(error.expected(), equalTo(TypeSets.type(Types.INT)));
+ assertThat(error.actual(), equalTo(Types.STRING));
+ }
}