aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenTryTests.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTryTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTryTests.java
index a0f71ed4..c64ed1d8 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTryTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTryTests.java
@@ -47,4 +47,34 @@ public class PatioCodeGenTryTests {
snapshotter.assertSnapshot(serialize(result));
}
+
+ @Test
+ public void effectHandlerIsPoppedBeforeReturn(Snapshotter snapshotter) throws IOException {
+ var namespaceName = new NamespaceName(List.of("Example", "Project"));
+ var effect = Effects.userDefined(namespaceName, "State");
+ var shidInstruction = Shid.try_(
+ effect,
+ List.of("a"),
+ Shid.block(List.of(
+ Shid.pushInt(42),
+ Shid.return_()
+ ))
+ );
+ var typeInfos = TypeCheckerContext.EMPTY
+ .addUserDefinedEffectInfo(
+ effect,
+ UserDefinedEffectInfo.builder()
+ .addMethod("a", FunctionType.builder().build())
+ .build()
+ )
+ .toTypeInfos();
+ var context = PatioCodeGenContext.forTypeInfos(typeInfos)
+ .stashGcRootStackIndex(new PatioLocalRef("gcRootStackIndex"))
+ .temporaryPush(new PatioLocalRef("other"))
+ .temporaryPush(new PatioLocalRef("handlerA"));
+
+ var result = PatioCodeGen.generateInstruction(shidInstruction, context);
+
+ snapshotter.assertSnapshot(serialize(result));
+ }
}