Juho Naalisvaara
10/21/2026, 11:22 AMVampire
10/21/2026, 11:58 AMyield by return it says
switch expression does not supportWhile it should be something likereturn
arrow-style switch does not supportNow that not every arrow-style switch is an expression.return
Vampire
10/21/2026, 12:03 PMyield if used as expression, so it is not bound to arrow-style but should indeed be bound to being an expression or not.
So I guess it should indeed complain about yield being used when arrow-style switch is used as statement and allow return instead, which then should probably also the behavior you mentioned.Juho Naalisvaara
10/21/2026, 12:11 PMstephen.watt
10/21/2026, 2:33 PMVampire
10/21/2026, 2:36 PMreturn in front of the switch, it is an expression and behaves like expected.
I still think the bug is, that the switch-statement in arrow-shape is considered an expression when it actually is a statement.
It should complain that there is yield and instead allow and require return and would then also behave as expected.paulk_asert
10/22/2026, 10:50 PMyield x to a plain expression, so a non-final yield is silently a no-op and execution falls through. The same lowering also affects value-discarded switches, and yield inside a loop within an arm now fails to compile.
Intended behaviour is that it's supported with early-exit semantics: the reclassification was only meant to change the encoding, and 4.x/5.x code had to use yield in block arms, so rejecting it would break working code. In return position yield should behave like return, otherwise like a break out of the switch. We'll raise a JIRA and target 6.0.1.
Workaround meanwhile: write return switch (...) { ... } (keeps it a switch expression), or restructure the arm so the only yield is the last statement (if/else with a yield in each branch).Vampire
10/22/2026, 10:56 PMreturn instead of yield and it says that in switch expression return is not supported.
I learned that now with 6, it is not a switch expression just because it has arrow-shape.
So I wonder, why does it tell about switch expression when it is a switch statement and also why is return not supported if it is now a switch statement. 😦paulk_asert
10/22/2026, 11:10 PM