Skip to content

[pigeon] ObjC generator doesn't handle nullable enum fields correctly #118733

Description

@stuartmorgan-g

The AllNullableTypes nullable enum field, which is

  AnEnum? aNullableEnum;

generates

@property(nonatomic, assign) AnEnum aNullableEnum;

That can't express a null value. Currently what happens is you get whatever 0 maps to in the enum, which is wrong.

IIRC @gaaclarke and I have discussed this in the past; using NSNumber like we do for other numeric types means clients have to cast, which isn't great. Options I can see include:

  • Use a sentinel value corresponding to null, but we'd have to be careful about naming collisions. (I think this was suggested at the time, I forget whether there are other problems we discussed with that approach.)
  • Generating a wrapper class in the case of a nullable enum, that would behave sort of like C++'s std::optional.

Activity

  1. added
    platform-iosiOS applications specifically
    packageflutter/packages repository. See also p: labels.
    p: pigeonrelated to pigeon messaging codegen tool
    P2Important issues not at the top of the work list
    on Jan 18, 2023
  2. stuartmorgan-g commented on Jan 18, 2023

    @stuartmorgan-g
    ContributorAuthor

    (Supporting this isn't that important in practice, since "nullable enum" is kind of a weird concept and thus unlikely to come up much in practice, and it's easy for clients to work around by making it non-nullable with an explicit null state, but we should at least be erroring out during generator validation instead of generating incorrect code.)

  3. stuartmorgan-g commented on Feb 8, 2023

    @stuartmorgan-g
    ContributorAuthor
    • Generating a wrapper class in the case of a nullable enum, that would behave sort of like C++'s std::optional.

    Since we don't have templating in ObjC, I think we'd need to generate a class per nullable enum. The class would be trivial though, something like:

    @interface NullableMyEnumType : NSObject
    @property(nonatomic, assign) MyEnumType value;
    @end
    

    The @implementation would be empty since property synthesis would take care of the rest.

  4. added a commit that references this issue on Aug 28, 2023
  5. github-actions commented on Sep 11, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  6. locked as resolved and limited conversation to collaborators on Sep 11, 2023
  7. added a commit that references this issue on Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listp: pigeonrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.platform-iosiOS applications specificallyteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions