diff options
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/typechecker/TypeCheckerCallTests.java | 48 |
1 files changed, 48 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 1dcfc36a..c7bbafaf 100644 --- a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerCallTests.java +++ b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerCallTests.java @@ -465,4 +465,52 @@ public class TypeCheckerCallTests { .withType(Types.constructedType(typeConstructor, List.of(Types.STRING))) ); } + + @Test + public void canCallGenericFunctionWithImplicitEffectArg() { + var untyped = UntypedCallNode.builder() + .withReceiver(Untyped.reference("twice")) + .withHasEffects(true) + .addPositionalArg(Untyped.reference("f")) + .build(); + var twiceType = FunctionType.builder() + .withTypeLevelParams(List.of( + EffectParam.forFunction(NamespaceName.of("Example"), "twice", "E") + )) + .addPositionalParam( + FunctionType.builder() + .withEffect(EffectParam.forFunction(NamespaceName.of("Example"), "twice", "E")) + .build() + ) + .withEffect(EffectParam.forFunction(NamespaceName.of("Example"), "twice", "E")) + .build(); + var context = TypeCheckerContext.EMPTY + .enterFunction( + P.map( + Map.entry( + "twice", + Variable.defined(twiceType, VariableType.VAL) + ), + Map.entry( + "f", + Variable.defined( + FunctionType.builder() + .withEffect(Effects.IO) + .build(), + VariableType.VAL + ) + ) + ), + Effects.IO, + Types.UNIT + ); + + var typed = typeCheckExpression(untyped, context); + + assertThat( + typed.value(), + isTypedCallNode() + .withHasEffects(true) + ); + } } |
