diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-03-02 15:39:10 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-03-02 15:39:10 +0000 |
| commit | f1089538f04062f71f530fa27396f6f446a0fc47 (patch) | |
| tree | 974fb1a56f4ee4ed5b95bc900232ee9c5e922f5d /src/test/java | |
| parent | 36aad08599b78b8ec034f567ee41ec7fa3dc5a02 (diff) | |
Support implicit effect args
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) + ); + } } |
