From 215b8bfcafcb701f684ce573b39e275caaf38698 Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Mon, 29 Jul 2024 09:15:47 +0200 Subject: [PATCH 1/2] Fix nested look-ahead switches. Closes #1810. --- spicy/toolchain/src/compiler/parser/parser.yy | 1 + .../output | 11 ++++++++++ .../types/unit/switch-nested-lahead.spicy | 20 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 tests/Baseline/spicy.types.unit.switch-nested-lahead/output create mode 100644 tests/spicy/types/unit/switch-nested-lahead.spicy diff --git a/spicy/toolchain/src/compiler/parser/parser.yy b/spicy/toolchain/src/compiler/parser/parser.yy index c51e05215..cc2b9d390 100644 --- a/spicy/toolchain/src/compiler/parser/parser.yy +++ b/spicy/toolchain/src/compiler/parser/parser.yy @@ -903,6 +903,7 @@ unit_switch_case | exprs ARROW unit_item { $$ = builder->typeUnitItemSwitchCase($1, {$3}, __loc__); } | '*' ARROW unit_item { $$ = builder->typeUnitItemSwitchCase(type::unit::Items{$3}, __loc__); } | ARROW unit_field { $$ = builder->typeUnitItemSwitchCase($2, __loc__); } + | ARROW unit_switch { $$ = builder->typeUnitItemSwitchCase($2, __loc__); } /* --- End of Spicy units --- */ diff --git a/tests/Baseline/spicy.types.unit.switch-nested-lahead/output b/tests/Baseline/spicy.types.unit.switch-nested-lahead/output new file mode 100644 index 000000000..a9837bf52 --- /dev/null +++ b/tests/Baseline/spicy.types.unit.switch-nested-lahead/output @@ -0,0 +1,11 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +foo::X { + a: a +} +foo::X { + b: b +} +foo::X { + c: c +} +[fatal error] terminating with uncaught exception of type spicy::rt::ParseError: no expected look-ahead token found (<...>/switch-nested-lahead.spicy:18:10-18:20) diff --git a/tests/spicy/types/unit/switch-nested-lahead.spicy b/tests/spicy/types/unit/switch-nested-lahead.spicy new file mode 100644 index 000000000..3aaa47d87 --- /dev/null +++ b/tests/spicy/types/unit/switch-nested-lahead.spicy @@ -0,0 +1,20 @@ +# @TEST-EXEC: spicyc %INPUT -j -o %INPUT.hlto +# @TEST-EXEC: ${SCRIPTS}/printf a | spicy-dump %INPUT.hlto >>output 2>&1 +# @TEST-EXEC: ${SCRIPTS}/printf b | spicy-dump %INPUT.hlto >>output 2>&1 +# @TEST-EXEC: ${SCRIPTS}/printf c | spicy-dump %INPUT.hlto >>output 2>&1 +# @TEST-EXEC-FAIL: ${SCRIPTS}/printf d | spicy-dump %INPUT.hlto >>output 2>&1 +# @TEST-EXEC: btest-diff output +# +# @TEST-DOC: Check nested switch constructs both using look-ahead. + +module foo; + +public type X = unit { + switch { + -> switch { + -> a: b"a"; + -> b: b"b"; + }; + -> c: b"c"; + }; + }; From e4ce31b793ff8438302e75e849fbf5ccf450cf1a Mon Sep 17 00:00:00 2001 From: Robin Sommer Date: Tue, 30 Jul 2024 14:29:00 +0200 Subject: [PATCH 2/2] Update CHANGES. [skip ci] --- CHANGES | 4 ++++ VERSION | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 203a71cb8..e9ad4054c 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +1.11.0-dev.280 | 2024-07-29 09:16:15 +0200 + + * GH-1810: Fix nested look-ahead switches. (Robin Sommer, Corelight) + 1.11.0-dev.279 | 2024-07-26 12:47:30 +0200 * GH-1808: Fix non-converging optimizer pass for used functions. (Benjamin Bannier, Corelight) diff --git a/VERSION b/VERSION index b0e8551d0..9976e181a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.11.0-dev.279 +1.11.0-dev.280