Skip to content

[pigeon] allow empty class#12181

Open
tarrinneal wants to merge 2 commits into
flutter:mainfrom
tarrinneal:allow-empty-class
Open

[pigeon] allow empty class#12181
tarrinneal wants to merge 2 commits into
flutter:mainfrom
tarrinneal:allow-empty-class

Conversation

@tarrinneal

Copy link
Copy Markdown
Contributor

instead of preventing it from being defined, I just made it work

@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 adds support for empty data classes in Pigeon across Dart, Java, Kotlin, and Objective-C generators, and bumps the package version to 27.2.0. Feedback on the changes suggests adding a blank line between the constructor and the serialization method in the generated Dart code for empty classes to improve readability.

Comment on lines +229 to 238
if (classDefinition.fields.isNotEmpty) {
indent.newln();
for (final NamedType field in getFieldsInSerializationOrder(classDefinition)) {
addDocumentationComments(indent, field.documentationComments, docCommentSpec);

final String datatype = addGenericTypes(field.type);
indent.writeln('$datatype ${field.name};');
indent.newln();
}
}

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

When generating Dart code for an empty class, there is no blank line written between the constructor and the _writeToList method. Adding a blank line here improves the readability of the generated code and aligns with Dart style guidelines for class member spacing.

Suggested change
if (classDefinition.fields.isNotEmpty) {
indent.newln();
for (final NamedType field in getFieldsInSerializationOrder(classDefinition)) {
addDocumentationComments(indent, field.documentationComments, docCommentSpec);
final String datatype = addGenericTypes(field.type);
indent.writeln('$datatype ${field.name};');
indent.newln();
}
}
if (classDefinition.fields.isNotEmpty) {
indent.newln();
for (final NamedType field in getFieldsInSerializationOrder(classDefinition)) {
addDocumentationComments(indent, field.documentationComments, docCommentSpec);
final String datatype = addGenericTypes(field.type);
indent.writeln('$datatype ${field.name};');
indent.newln();
}
} else {
indent.newln();
}

@github-actions github-actions Bot removed the CICD Run CI/CD label Jul 14, 2026
@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

Looks like Linux, Windows, and Obj-C tests are all sad.

@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 a couple of small tweaks.

Some of the output is a little silly (like the string concatenation of Foo( and ) as separate steps with nothing in between for to-string methods), but nothing that's worth adding complexity to the generators for other than the one case noted below where it's creating an unused variable.

(nullable NSDictionary<NSNumber *, FLTAllNullableTypesWithoutRecursion *> *)
nullableClassMap;
nullableClassMap
anEmptyClass:(nullable FLTAnEmptyClass *)anEmptyClass;

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 Obj-C test failure looks like a call site wasn't updated for this change.

if (![object isKindOfClass:[self class]]) {
return NO;
}
FLTAnEmptyClass *other = (FLTAnEmptyClass *)object;

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.

This shouldn't be output when there are no fields, since it'll trigger unused variable warnings in some projects.

List? testList;
}

class AnEmptyClass {}

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.

You need to move this before AllClassesWrapper because of flutter/flutter#128330. That may well be all you need to fix Linux and Windows.

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

(Now with the right radio button selected.)

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