Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue of incorrect switch cases with identical bodies when mixing… #6792

Merged
merged 1 commit into from
May 30, 2024

Conversation

cristianoc
Copy link
Collaborator

… object and array.

Fixes #6789

The issue happens when 2 cases, here Object and Array, have identical body (here Console.log(v)). The switch-generation code, which was not designed with untagged unions in mind, merges the two cases into one (and makes one of the two empty).

However, for Object and Array, what's generated is not a straight switch, but a mix of if-then-else and switch. This means that the Object and Array cases are apart in the generated code, and merging them (making one empty) is wrong.

… object and array.

Fixes #6789

The issue happens when 2 cases, here `Object` and `Array`, have identical body (here `Console.log(v)`).
The switch-generation code, which was not designed with untagged unions in mind, merges the two cases into one (and makes one of the two empty).

However, for `Object` and `Array`, what's generated is not a straight switch, but a mix of `if-then-else` and `switch`. This means that the `Object` and `Array` cases are apart in the generated code, and merging them (making one empty) is wrong.
@cristianoc cristianoc force-pushed the switch-untagged-merged-cases branch from f027b1a to 7856979 Compare May 29, 2024 16:21
@cristianoc cristianoc requested review from jfrolich and zth May 29, 2024 16:27
Copy link
Collaborator

@zth zth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing!

@cristianoc cristianoc merged commit 326fd32 into master May 30, 2024
19 checks passed
@cknitt cknitt deleted the switch-untagged-merged-cases branch May 30, 2024 06:26
@jfrolich
Copy link

Really appreciated, amazing! ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug in handling the JSON unboxed type when switching on it
3 participants