From 3d7bef187c346954e88c6105584bf79d32ef6060 Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Sat, 19 Nov 2022 23:14:09 +0100 Subject: [PATCH] Matchers: Don't return twice when value to capture is missing We called return_from_matcher once inside matcher_evaluate_capturing_instruction and outside of it. That way we returned not to the parent call stack entry but to the grandparent. --- src/CMakeLists.txt | 1 + src/eval.c | 1 - src/functional-tests/variadic-functions.at | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/functional-tests/variadic-functions.at diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3abf973..11d758a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -67,6 +67,7 @@ functionaltest("while") functionaltest("eq") functionaltest("chained-assignments") functionaltest("dictionary-assignments") +functionaltest("variadic-functions") install(TARGETS apfl DESTINATION lib) install(TARGETS apfl-bin DESTINATION bin) diff --git a/src/eval.c b/src/eval.c index 5d877b1..31be76d 100644 --- a/src/eval.c +++ b/src/eval.c @@ -1159,7 +1159,6 @@ matcher_evaluate_capturing_instruction( struct apfl_value cur; if (!matcher_current_val(ctx, cse, &cur)) { - return_from_matcher(ctx, false); return false; } diff --git a/src/functional-tests/variadic-functions.at b/src/functional-tests/variadic-functions.at new file mode 100644 index 0000000..f425772 --- /dev/null +++ b/src/functional-tests/variadic-functions.at @@ -0,0 +1,18 @@ +===== script ===== +foo = { +x y z -> 3 +x y -> 2 +x -> 1 +-> 0 +} + +print (foo 1 1 1) +print (foo 1 1) +print (foo 1) +print (foo) + +===== output ===== +3 +2 +1 +0