[pigeon] updates toString and isNullish methods#11625
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates Pigeon to version 26.4.0, introducing automatic generation of toString (or equivalent) methods for data classes across all supported languages. It also refines the Swift isNullish utility to handle nested optional values. Review feedback highlights a critical logic error in the C++ generator that results in unbalanced braces and corrupted code, along with a compilation issue when handling C++ enums. Additionally, for Swift, the feedback identifies a redundant protocol conformance error in subclasses and suggests using String(describing:) to prevent compiler warnings during string interpolation of optional fields.
| indent.writeln('ss << *$name;'); | ||
| } | ||
| }); | ||
| indent.nest(1, () { | ||
| indent.writeln('ss << "null";'); | ||
| }); | ||
| } else { | ||
| if (field.type.isClass) { | ||
| indent.writeln('ss << $name.ToString();'); | ||
| } else { | ||
| indent.writeln('ss << $name;'); |
There was a problem hiding this comment.
There was a problem hiding this comment.
Gemini is correct here. You'll also need custom handling of maps, and maybe lists.
| final Iterable<String> fieldStrings = classDefinition.fields.map(( | ||
| NamedType field, | ||
| ) { | ||
| return '${field.name}: \\(${field.name})'; |
There was a problem hiding this comment.
In Swift, string interpolation of optional values triggers a compiler warning (e.g., "Expression implicitly coerced from 'String?' to 'Any'"). It is recommended to wrap optional fields in String(describing:) to silence this warning and provide a consistent string representation.
| return '${field.name}: \\(${field.name})'; | |
| return '${field.name}: \(String(describing: ${field.name}))'; |
stuartmorgan-g
left a comment
There was a problem hiding this comment.
The native unit tests should have a test that calls the to-string method for a test object and ensure that the expected string results, so that we are validating that the methods do what we expect (and also have a clear snapshot of what the expected output actually is).
| indent.writeln('ss << *$name;'); | ||
| } | ||
| }); | ||
| indent.nest(1, () { | ||
| indent.writeln('ss << "null";'); | ||
| }); | ||
| } else { | ||
| if (field.type.isClass) { | ||
| indent.writeln('ss << $name.ToString();'); | ||
| } else { | ||
| indent.writeln('ss << $name;'); |
There was a problem hiding this comment.
Gemini is correct here. You'll also need custom handling of maps, and maybe lists.
| NamedType field, | ||
| ) { | ||
| if (_usesPrimitive(field.type)) { | ||
| return '@(self.${field.name})'; |
There was a problem hiding this comment.
FWIW it would be conceptually cleaner to use the right format string for each primitive type, rather than boxing them just to print them as objects. But since this is just a nice-to-have utility method, and Obj-C isn't a development focus, it's fine to leave as-is.
There was a problem hiding this comment.
lmk if my change is what you had in mind.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements toString (or equivalent) method generation for data classes across all supported Pigeon generators, including Dart, Java, Kotlin, Swift, Objective-C, C++, and GObject. It also updates the Swift isNullish helper to correctly handle double-nested Any? values and adds new list-based echo methods to the core integration tests. Feedback identifies a missing nullability check for boolean fields in the GObject generator and potential integer truncation issues in the Objective-C description implementation on 32-bit platforms. Additionally, a suggestion was made to maintain field name consistency in GObject string representations.
stuartmorgan-g
left a comment
There was a problem hiding this comment.
Changes LGTM, but it looks like a project file is still referring to AllDatatypesTest.m instead of DataClassMethodsTest.m.
|
@stuartmorgan-g this is done, you can submit or review. |
prequel pr to flutter#11352 to land non NI changes to simplify pr.
…r#187784) flutter/packages@bd297cf...1b56cde 2026-06-10 stuartmorgan@google.com [shared_preferences] Switch to Kotlin Pigeon (flutter/packages#11661) 2026-06-10 tarrinneal@gmail.com [pigeon] updates toString and isNullish methods (flutter/packages#11625) 2026-06-10 stuartmorgan@google.com [various] Remove moved packages (flutter/packages#11850) 2026-06-10 engine-flutter-autoroll@skia.org Roll Flutter from 1bdf4af to 66aaa9a (30 revisions) (flutter/packages#11876) 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 flutter-ecosystem@google.com 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
…r#187784) flutter/packages@bd297cf...1b56cde 2026-06-10 stuartmorgan@google.com [shared_preferences] Switch to Kotlin Pigeon (flutter/packages#11661) 2026-06-10 tarrinneal@gmail.com [pigeon] updates toString and isNullish methods (flutter/packages#11625) 2026-06-10 stuartmorgan@google.com [various] Remove moved packages (flutter/packages#11850) 2026-06-10 engine-flutter-autoroll@skia.org Roll Flutter from 1bdf4af to 66aaa9a (30 revisions) (flutter/packages#11876) 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 flutter-ecosystem@google.com 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
prequel pr to #11352 to land non NI changes to simplify pr.