Skip to content

Conversation

andrea689
Copy link

This PR fixes an issue where switch expressions over sealed class unions did not properly narrow the type of this to the matched subtype.

In Dart, this does not automatically change its static type inside a switch pattern case — even when the case pattern matches a specific subclass. As a result, generated code that directly passed this to subtype-specific serialization functions (e.g. _$SubtypeToJson(this)) failed to compile without explicit casting.

This PR updates the code generation logic to ensure the correct subtype is used in these cases by explicitly binding or casting this to the appropriate subclass within each switch case.

@Carapacik Carapacik closed this Oct 18, 2025
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.

2 participants