From 8f0f5c7f448b49652d4a3d6be70b0e867859a6d0 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 22 Dec 2024 20:44:49 +0000 Subject: Support any result type for Patio try --- .../shedlang/compiler/patio/PatioExampleTests.java | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java index e1566c99..f7dcbcb5 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java @@ -790,6 +790,49 @@ public abstract class PatioExampleTests { )); } + @Test + public void tryCanHaveMultipleResults() throws IOException, InterruptedException { + var patioFunction = PatioFunctionDefinition.builder() + .withName(FUNCTION_NAME) + .withReturnType(PatioTypes.VOID) + .addLocal(Patio.val("r1", PatioTypes.INT)) + .addLocal(Patio.val("r2", PatioTypes.INT)) + .addLocal(Patio.val("e1", PatioTypes.INT)) + .addLocal(Patio.val("e2", PatioTypes.INT)) + .addBodyInstruction(Patio.try_( + List.of(Patio.localRef("r1"), Patio.localRef("r2")), + List.of( + Patio.catchClause( + "Error", + Patio.localRef("e1"), + Patio.block( + List.of(), + List.of(Patio.intConst(11), Patio.intConst(12)) + ) + ) + ), + Patio.block( + List.of(), + List.of(Patio.intConst(1), Patio.intConst(2)) + ) + )) + .addBodyInstruction(emitInt(Patio.localRef("r1"))) + .addBodyInstruction(emitInt(Patio.localRef("r2"))) + .addBodyInstruction(Patio.returnVoid()) + .build(); + var patio = Patio.compilationUnit(List.of( + Patio.exceptionTypeDefinition("Error", PatioTypes.INT), + patioFunction + )); + + var result = run(patio); + + assertThat(result, isSequence( + isInt(1), + isInt(2) + )); + } + @Test public void vars() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() -- cgit v1.2.3