Skip to content

Conversation

@devgianlu
Copy link
Contributor

This PR ensures that custom enums are encoded as the expected Long type in the Kotlin generator.

Without this change it is not possible to perform encoding <-> decoding in Kotlin, because enums are generated to have an Int raw value and encoded without first casting to Long.

Fixes: flutter/flutter#176081

Pre-Review Checklist

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-assist bot 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

  1. 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

Copy link

@gemini-code-assist gemini-code-assist bot left a 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.

@devgianlu devgianlu changed the title [pigeon] Fix encode logic for custom enum in Kotlin generator [pigeon] Encode custom enum as long in Kotlin generator Sep 26, 2025
@stuartmorgan-g
Copy link
Collaborator

From triage: Ping @tarrinneal on this review

Copy link
Contributor

@tarrinneal tarrinneal left a 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

Copy link
Collaborator

@stuartmorgan-g stuartmorgan-g left a 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
Copy link
Collaborator

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.

Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

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

Actual approval

@tarrinneal tarrinneal added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 6, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 6, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented Nov 6, 2025

autosubmit label was removed for flutter/packages/10085, because Pull request flutter/packages/10085 is not in a mergeable state.

@tarrinneal tarrinneal added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 6, 2025
@auto-submit auto-submit bot merged commit f1b2af6 into flutter:main Nov 6, 2025
80 checks passed
@devgianlu devgianlu deleted the patch-1 branch November 6, 2025 21:36
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 7, 2025
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Nov 7, 2025
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
IvoneDjaja pushed a commit to IvoneDjaja/flutter that referenced this pull request Nov 22, 2025
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
reidbaker pushed a commit to AbdeMohlbi/flutter that referenced this pull request Dec 10, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App p: pigeon platform-android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[pigeon] ClassCastException when round-tripping enums within Kotlin

3 participants