-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[pigeon] Encode custom enum as long in Kotlin generator #10085
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request addresses a ClassCastException in the Kotlin generator by ensuring custom enums are encoded as Long instead of Int. The core change correctly adds a .toLong() call during the serialization of enum raw values. The PR is well-structured, including updates to the version number in pubspec.yaml and generator_tools.dart, a clear entry in CHANGELOG.md, and a new test expectation to verify the fix and prevent regressions. The changes are correct and effectively resolve the reported issue.
|
From triage: Ping @tarrinneal on this review |
tarrinneal
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good with one new test
...atform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt
Show resolved
Hide resolved
stuartmorgan-g
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with one naming nit.
(@tarrinneal this will still need your actual approval bit to land once that's done.)
| void writeEncodeLogic(EnumeratedType customType) { | ||
| final String encodeString = | ||
| customType.type == CustomTypes.customClass ? 'toList()' : 'raw'; | ||
| customType.type == CustomTypes.customClass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tarrinneal At some point we should consider converting statements like these to the new expression switches (final String encodeString = switch (customType.type) {...};), so that if we ever add another custom type the compiler will find all the places we need to adjust the logic, instead of having the new type randomly opted into one or the other existing codepath everywhere.
...atform_tests/test_plugin/android/src/test/kotlin/com/example/test_plugin/AllDatatypesTest.kt
Outdated
Show resolved
Hide resolved
tarrinneal
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actual approval
|
autosubmit label was removed for flutter/packages/10085, because Pull request flutter/packages/10085 is not in a mergeable state. |
flutter/packages@f13bad3...3caa48b 2025-11-06 [email protected] [go_router] Migrates test for leak testing (flutter/packages#10276) 2025-11-06 [email protected] Run tests on macOS 15.5 or 15.7 (flutter/packages#10336) 2025-11-06 [email protected] [pigeon] Encode custom enum as long in Kotlin generator (flutter/packages#10085) 2025-11-06 [email protected] [tool] Ensure that all packages format with correct language version (flutter/packages#10374) 2025-11-06 [email protected] Roll Flutter from e5d5c01 to c5e809a (29 revisions) (flutter/packages#10369) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/packages@f13bad3...3caa48b 2025-11-06 [email protected] [go_router] Migrates test for leak testing (flutter/packages#10276) 2025-11-06 [email protected] Run tests on macOS 15.5 or 15.7 (flutter/packages#10336) 2025-11-06 [email protected] [pigeon] Encode custom enum as long in Kotlin generator (flutter/packages#10085) 2025-11-06 [email protected] [tool] Ensure that all packages format with correct language version (flutter/packages#10374) 2025-11-06 [email protected] Roll Flutter from e5d5c01 to c5e809a (29 revisions) (flutter/packages#10369) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/packages@f13bad3...3caa48b 2025-11-06 [email protected] [go_router] Migrates test for leak testing (flutter/packages#10276) 2025-11-06 [email protected] Run tests on macOS 15.5 or 15.7 (flutter/packages#10336) 2025-11-06 [email protected] [pigeon] Encode custom enum as long in Kotlin generator (flutter/packages#10085) 2025-11-06 [email protected] [tool] Ensure that all packages format with correct language version (flutter/packages#10374) 2025-11-06 [email protected] Roll Flutter from e5d5c01 to c5e809a (29 revisions) (flutter/packages#10369) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
This PR ensures that custom enums are encoded as the expected
Longtype in the Kotlin generator.Without this change it is not possible to perform encoding <-> decoding in Kotlin, because enums are generated to have an
Intraw value and encoded without first casting toLong.Fixes: flutter/flutter#176081
Pre-Review Checklist
[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2 ↩3