Skip to content

[pigeon] updates toString and isNullish methods#11625

Merged
auto-submit[bot] merged 17 commits into
flutter:mainfrom
tarrinneal:toString
Jun 10, 2026
Merged

[pigeon] updates toString and isNullish methods#11625
auto-submit[bot] merged 17 commits into
flutter:mainfrom
tarrinneal:toString

Conversation

@tarrinneal

Copy link
Copy Markdown
Contributor

prequel pr to #11352 to land non NI changes to simplify pr.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread packages/pigeon/lib/src/cpp/cpp_generator.dart Outdated
Comment on lines +1161 to +1171
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;');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

C++ enum class types do not support the << operator for std::ostream by default. If a data class contains an enum field, the generated ToString method will fail to compile. You should check if the field is an enum and cast it to its underlying integer type before appending it to the stream.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Gemini is correct here. You'll also need custom handling of maps, and maybe lists.

Comment thread packages/pigeon/lib/src/swift/swift_generator.dart Outdated
final Iterable<String> fieldStrings = classDefinition.fields.map((
NamedType field,
) {
return '${field.name}: \\(${field.name})';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
return '${field.name}: \\(${field.name})';
return '${field.name}: \(String(describing: ${field.name}))';

@github-actions github-actions Bot removed the CICD Run CI/CD label May 1, 2026
@stuartmorgan-g stuartmorgan-g added the CICD Run CI/CD label May 4, 2026

@stuartmorgan-g stuartmorgan-g left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Comment on lines +1161 to +1171
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;');

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Gemini is correct here. You'll also need custom handling of maps, and maybe lists.

Comment thread packages/pigeon/lib/src/cpp/cpp_generator.dart Outdated
Comment thread packages/pigeon/lib/src/dart/dart_generator.dart Outdated
Comment thread packages/pigeon/lib/src/gobject/gobject_generator.dart Outdated
NamedType field,
) {
if (_usesPrimitive(field.type)) {
return '@(self.${field.name})';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

lmk if my change is what you had in mind.

Comment thread packages/pigeon/platform_tests/test_plugin/linux/pigeon/core_tests.gen.cc Outdated
@github-actions github-actions Bot removed the CICD Run CI/CD label May 7, 2026
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 11, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 12, 2026
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 13, 2026
@tarrinneal

Copy link
Copy Markdown
Contributor Author

/gemini review

@tarrinneal tarrinneal requested a review from stuartmorgan-g May 13, 2026 02:48

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread packages/pigeon/lib/src/gobject/gobject_generator.dart Outdated
Comment thread packages/pigeon/lib/src/objc/objc_generator.dart
Comment thread packages/pigeon/lib/src/objc/objc_generator.dart
Comment thread packages/pigeon/lib/src/gobject/gobject_generator.dart Outdated
@github-actions github-actions Bot removed the CICD Run CI/CD label May 14, 2026
@tarrinneal tarrinneal added CICD Run CI/CD labels May 14, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 3, 2026

@stuartmorgan-g stuartmorgan-g left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM with nits.

Comment thread packages/pigeon/lib/src/gobject/gobject_generator.dart Outdated
Comment thread packages/pigeon/lib/src/gobject/gobject_generator.dart Outdated
Comment thread packages/pigeon/CHANGELOG.md Outdated
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jun 5, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 5, 2026
@tarrinneal tarrinneal added the CICD Run CI/CD label Jun 5, 2026
@tarrinneal tarrinneal requested a review from stuartmorgan-g June 5, 2026 19:44
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 5, 2026
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jun 5, 2026

@stuartmorgan-g stuartmorgan-g left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Changes LGTM, but it looks like a project file is still referring to AllDatatypesTest.m‎ instead of DataClassMethodsTest.m.

@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 8, 2026
@tarrinneal tarrinneal added the CICD Run CI/CD label Jun 8, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 9, 2026
@tarrinneal tarrinneal added the CICD Run CI/CD label Jun 9, 2026
@tarrinneal tarrinneal added CICD Run CI/CD and removed CICD Run CI/CD labels Jun 10, 2026
@tarrinneal

Copy link
Copy Markdown
Contributor Author

@stuartmorgan-g this is done, you can submit or review.

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 10, 2026
@auto-submit auto-submit Bot merged commit 5571d4f into flutter:main Jun 10, 2026
87 checks passed
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
prequel pr to flutter#11352 to land non NI changes to simplify pr.
pull Bot pushed a commit to Spencerx/flutter that referenced this pull request Jun 11, 2026
…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
via-guy pushed a commit to via-guy/flutter that referenced this pull request Jun 26, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants