aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-07-02 12:23:41 +0100
committerMichael Williamson <mike@zwobble.org>2023-07-02 12:23:41 +0100
commitff0b422cddead23865f0f5662bd9a4d2abef462d (patch)
treed02d8164b7a9a2ab3ebe841584ad3809d9116630 /src/test/java
parent71a8ca11b03331a92bb271cbd1fbcb877e587300 (diff)
Check call to function without effects has no effects
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/typechecker/TypeCheckerCallTests.java24
1 files changed, 24 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 ad1ab07e..ffbc3c29 100644
--- a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerCallTests.java
+++ b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerCallTests.java
@@ -2,6 +2,9 @@ package org.shedlang.compiler.typechecker;
import org.junit.jupiter.api.Test;
import org.shedlang.compiler.ast.untyped.Untyped;
+import org.shedlang.compiler.ast.untyped.UntypedArgsNode;
+import org.shedlang.compiler.ast.untyped.UntypedCallNode;
+import org.shedlang.compiler.sources.Sources;
import org.shedlang.compiler.typechecker.errors.*;
import org.shedlang.compiler.typechecker.typesets.TypeSets;
import org.shedlang.compiler.types.Effects;
@@ -274,4 +277,25 @@ public class TypeCheckerCallTests {
assertThat(error.effect(), equalTo(Effects.IO));
}
+
+ @Test
+ public void givenFunctionHasNoEffectWhenCallingFunctionWithExplicitEffectsThenErrorIsThrown() {
+ var untyped = new UntypedCallNode(
+ Untyped.reference("f"),
+ new UntypedArgsNode(List.of(), List.of(), Sources.NULL),
+ true,
+ Sources.NULL
+ );
+ var functionType = FunctionType.builder()
+ .withEffect(Effects.NONE)
+ .withReturnType(Types.UNIT)
+ .build();
+ var context = TypeCheckerContext.EMPTY
+ .enter(P.map(Map.entry("f", functionType)));
+
+ assertThrows(
+ FunctionHasNoEffectsError.class,
+ () -> TypeChecker.typeCheckExpression(untyped, context)
+ );
+ }
}