Skip to content

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

@stuartmorgan-g

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.

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