Skip to content

[pigeon] primitive enums#4580

Merged
auto-submit[bot] merged 15 commits intoflutter:mainfrom
tarrinneal:enums
Aug 28, 2023
Merged

[pigeon] primitive enums#4580
auto-submit[bot] merged 15 commits intoflutter:mainfrom
tarrinneal:enums

Conversation

@tarrinneal
Copy link
Contributor

@tarrinneal tarrinneal commented Jul 28, 2023

Adds support for enums as parameters and return types.

Dart, C++, Java, Kotlin, Objective-C, and swift:
Primitive synchronous non-null
Primitive synchronous nullable
Primitive asynchronous non-null
Primitive asynchronous nullable
Primitive Flutter api non-null
Primitive flutter api nullable

Objective-C:
Class property nullable

Also fixes an issue with nullable enums in classes on objc. This fix required a breaking change that nested all nullable enums in a wrapper class to allow nullability.

Also adds the ability to format files before tests run (to make my life better)

Also replaces #4756

Also adds objc prefixes to enums

fixes: flutter/flutter#87307
fixes: flutter/flutter#118733

@tarrinneal tarrinneal force-pushed the enums branch 5 times, most recently from 0f05d58 to 6958a07 Compare August 8, 2023 19:32
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.

Nice! Various nits and suggestions, but it's really great to see comprehensive enum support.

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!

(The more I see FooEnumBox the less I like that suggestion, but I still don't have a better idea. I'll just take comfort in the fact that nullable enums will probably be rare, and ObjC generation is likely decreasing, so the intersection should be rare and shrinking.)

} else {
indent.writeln('std::optional<${hostType.datatype}> $argName;');
indent.writeln(
'const std::optional<${hostType.datatype}> $argName = $encodableArgName.IsNull() ? std::optional<${hostType.datatype}>() : std::make_optional<${hostType.datatype}>(static_cast<${hostType.datatype}>(${argName}_value));');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can std::optional<${hostType.datatype}>() just be std::nullopt? I think that works in ternaries.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It didn't work when I tried it in this context, but it's possible I had a different issue.

@tarrinneal
Copy link
Contributor Author

(The more I see FooEnumBox the less I like that suggestion, but I still don't have a better idea. I'll just take comfort in the fact that nullable enums will probably be rare, and ObjC generation is likely decreasing, so the intersection should be rare and shrinking.)

better or worse than wrapper?

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.

New changes also LGTM. Thanks for fixing that existing missing prefix issue; I'm surprised/embarassed I didn't notice it when doing conversions.

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.

[pigeon] ObjC generator doesn't handle nullable enum fields correctly pigeon: implement primitive enum return values and arguments

2 participants