From f1089538f04062f71f530fa27396f6f446a0fc47 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 2 Mar 2024 15:39:10 +0000 Subject: Support implicit effect args --- .../compiler/typechecker/TypeCheckerCallTests.java | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src/test/java') 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) + ); + } } -- cgit v1.2.3