Skip to content

Conversation

Ladicek
Copy link
Contributor

@Ladicek Ladicek commented Jun 13, 2025

  1. Add BlockCreator.switch_() and switchEnum() overloads that accept Class as the switch expression type, in addition to ClassDesc. Often, the type is statically known and easier to express as Class.

  2. Add validation that at least one case or default branch is added to a switch. If none is added, an exception is thrown early.

  3. Allow hash-based switch implementations to have no case branches, only a default branch. This condition occurs in practice when case branches are generated based on an external list of objects. Such lists may easily be empty. This has always been allowed for value-based switch implementations (called "perfect hash" based here).

  4. Let switch expressions (switch with a non-void type) always fall through. This allows (and, in fact, requires) using them as actual expressions.

    Note that switch statements (switch with a void type) behave as before: if no branch may fall through, the entire switch may not either.

Tests are added for items 3 and 4.

1. Add `BlockCreator.switch_()` and `switchEnum()` overloads that accept
   `Class` as the `switch` expression type, in addition to `ClassDesc`.
   Often, the type is statically known and easier to express as `Class`.
2. Add validation that at least one `case` or `default` branch is added
   to a `switch`. If none is added, an exception is thrown early.
3. Allow hash-based `switch` implementations to have no `case` branches,
   only a `default` branch. This condition occurs in practice when `case`
   branches are generated based on an external list of objects. Such lists
   may easily be empty. This has always been allowed for value-based `switch`
   implementations (called "perfect hash" based here).
4. Let `switch` expressions (`switch` with a non-`void` type) always fall
   through. This allows (and, in fact, requires) using them as actual
   expressions.

   Note that `switch` statements (`switch` with a `void` type) behave as
   before: if no branch may fall through, the entire `switch` may not either.

Tests are added for items 3 and 4.
@Ladicek Ladicek added the 2.x Issue applies to Gizmo 2.x label Jun 13, 2025
@Ladicek Ladicek moved this to In Progress in WG - Gizmo 2 Jun 13, 2025
@dmlloyd dmlloyd merged commit e6e4b4a into quarkusio:main Jun 13, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in WG - Gizmo 2 Jun 13, 2025
@dmlloyd
Copy link
Member

dmlloyd commented Jun 13, 2025

Good catch on the switch expression fall-through, I didn't think of that.

@Ladicek Ladicek deleted the improve-switch branch June 13, 2025 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x Issue applies to Gizmo 2.x
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants