diff --git a/CHANGES b/CHANGES index 203a71cb8..7b3e328a3 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +1.11.0-dev.282 | 2024-07-30 17:02:31 +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..5860a871d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.11.0-dev.279 +1.11.0-dev.282 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"; + }; + };