Skip to content

[pigeon] C++ generator makes uncompilable code for returning a list #105057

Closed
flutter/packages
#2270

Description

@stuartmorgan-g

I defined an API of the form:

List<String?> foo(...);

and the resulting C++ code doesn't compile for me. It gets translated to

virtual ErrorOr<std::unique_ptr<flutter::EncodableList>> Foo(...);

which doesn't work because ErrorOr<T> has a const T& rhs constructor that calls T(rhs), which is a deleted copy constructor for std::unique_ptr.

I'm confused about how this new variant of ErrorOr is intended to work now that I'm looking at it in actual use. v is a variant whose types include a T and a std::unique_ptr<T>, which in this case would be a nested double unique_ptr which seems unlikely to be the intent. @azchohfi what was the intended behavior here?

Activity

  1. added
    platform-windowsBuilding on or for Windows specifically
    packageflutter/packages repository. See also p: labels.
    p: pigeonrelated to pigeon messaging codegen tool
    P1High-priority issues at the top of the work list
    on May 31, 2022
  2. azchohfi commented on May 31, 2022

    @azchohfi

    This is how I tested this on the video player:

        std::unique_ptr<TextureMessage> textureMessage = std::make_unique<TextureMessage>();
        textureMessage->set_texture_id(textureId);
        return ErrorOr<TextureMessage>::MakeWithUniquePtr(std::move(textureMessage));
  3. azchohfi commented on May 31, 2022

    @azchohfi

    I'm sorry, but I didn't understand what you meant by nested double unique_ptr.
    Why is the generated code an issue? I'm trying to understand the scenario here.
    The only things not being passed by reference are bool, int64_t and double. Everything else is by reference.
    I tried not to use unique_ptr for everything, but a variant is not permitted to hold references, neither is std::optional.

  4. stuartmorgan-g commented on May 31, 2022

    @stuartmorgan-g
    ContributorAuthor

    This is how I tested this on the video player:

        std::unique_ptr<TextureMessage> textureMessage = std::make_unique<TextureMessage>();
        textureMessage->set_texture_id(textureId);
        return ErrorOr<TextureMessage>::MakeWithUniquePtr(std::move(textureMessage));

    It sounds like the intent was that the generated return type in my case should have been ErrorOr<EncodableList> rather than ErrorOr<unique_ptr<EncodableList>> then. I'll take a look soon to see what went wrong (and get more tests spun up to cover return types).

    The issue is that once T for ErrorOr<T> is itself a unique_ptr, as happened for me, things fall apart.

  5. stuartmorgan-g commented on Jun 1, 2022

    @stuartmorgan-g
    ContributorAuthor

    Hm, the more I look at ErrorOr the more confused I am. I missed that MakeWithUniquePtr returns a different type than the type it's called with. And there doesn't appear to ever be a way to use the unique_ptr variant flavor of v given the implementation of get?

    It looks like the intent of v was that it could have a copy or a unique ptr and either would work as a value, but that's not actually what the implementation does. I'll try adjusting it to fit that approach and see how it works.

  6. stuartmorgan-g commented on Jun 1, 2022

    @stuartmorgan-g
    ContributorAuthor

    I think I have a workable version of this using a move-based alternate constructor instead of a unique_ptr version. (I'm still working through some unrelated issues to get and end-to-end test going.)

  7. github-actions commented on Aug 4, 2022

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

  8. locked as resolved and limited conversation to collaborators on Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P1High-priority issues at the top of the work listp: pigeonrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.platform-windowsBuilding on or for Windows specifically

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions