diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-12-19 13:39:01 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-12-19 13:39:01 +0000 |
| commit | 1c89809ea205455ec78ad89152b37bd15893e7c9 (patch) | |
| tree | 708b25ff70513e5de56adadb6f56b7d577d06c15 /src/test/java | |
| parent | 9a2d749472c0de64cee12b1dc6c1556536bde93f (diff) | |
Handle returns from try bodies
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioCodeGenTryTests.java | 30 |
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)); + } } |
