Skip to content

[Pigeon] bool type as a parameter generates unusable dart code #62463

Closed

Description

@dalewking

@gaaclarke

Steps to Reproduce

  1. Start with this example file copied to the root of a project that is setup for pigeon
  2. flutter pub run pigeon --input message.dart --dart_out lib/message.dart
  3. This works fine and generates usable dart code
  4. Add method to an API that has a bool parameter as in:
    @HostApi()
    abstract class NestedApi {
      SearchReply search(Nested nested);
      void test(bool testBool);
    }
  1. flutter pub run pigeon --input message.dart --dart_out lib/message.dart

Expected results:

The generated code adds the method and

Actual results:

The generated dart code now adds this bool class which makes the code unusable because it is used instead of normal Dart bool:

class bool {
  // ignore: unused_element
  Map<dynamic, dynamic> _toMap() {
    final Map<dynamic, dynamic> pigeonMap = <dynamic, dynamic>{};
    return pigeonMap;
  }
  // ignore: unused_element
  static bool _fromMap(Map<dynamic, dynamic> pigeonMap) {
    final bool result = bool();
    return result;
  }
}

In addition the classes that had bool in them are changed to this bool class so instead of this:

pigeonMap['aBool'] = aBool;

you get:

pigeonMap['aBool'] = aBool._toMap();

Activity

  1. dalewking commented on Jul 29, 2020

    @dalewking
    Author

    It isn't just bool. It will do the same thing for int or String.

  2. dalewking commented on Jul 29, 2020

    @dalewking
    Author

    And it isn't just the dart code, I see the same in generated JVM code as well and I assume in the Objective-C code as well.

    So it looks like you only support passing classes as parameters. Which if that is the direction you want to go then it should generate an error not generate unusable code.

  3. added
    packageflutter/packages repository. See also p: labels.
    p: pigeonrelated to pigeon messaging codegen tool
    on Jul 29, 2020
  4. gaaclarke commented on Jul 29, 2020

    @gaaclarke
    Member

    Hi @dalewking, yep currently parameters need to be void or a class. It definitely should give a good error for this.

    There was talk of supporting single parameters at some point, too. That might be nice at some point too but is lower priority.

  5. dalewking commented on Jul 30, 2020

    @dalewking
    Author
  6. xster commented on Jul 30, 2020

    @xster
    Contributor

    @dalewking I think they're all valid feature requests. Could you file individual bugs for those features?

    Can we turn this bug into a feature request to support primitives in Pigeon?

  7. gaaclarke commented on Jul 30, 2020

    @gaaclarke
    Member

    @dalewking Thanks, most of those were on my radar.

    The template idea is interesting. I hadn't considered that one, thanks. Like @xster said turning these into feature requests would be helpful.

  8. dalewking commented on Jul 30, 2020

    @dalewking
    Author

    Note I had found mustache4dart and i thought was not powerful enough, but according to the site it passes all the specification tests so I may have dismissed it too quickly. I since discovered a different mustache dart library that should also do the trick.

    Another feature I would like is the ability to support not having to use command line parameters. You have the configuration method that can do most of it, but that only works if you specify input parameter. So I am thinking of perhaps you look for a pigeon_config.dart and include it and/or look for a pigeons directory and run for every dart file in there.

    You are also setup to only really support one generation, not multiple in one run. i would kind of like to be able to generate more than one, but that may be a sign that I should instead split things into separate plugins.

  9. dalewking commented on Jul 30, 2020

    @dalewking
    Author

    I will try to create feature requests, but I think this bug request could be used as a request to report an error instead of just blindly creating classes that replace the built in dart classes.

    I think switching to templates might be a good place to start as it might make some of the other features easier in the long run.

  10. dalewking commented on Jul 30, 2020

    @dalewking
    Author

    This might be a better and more powerful template engine than mustache: https://pub.dev/packages/liquid_engine

  11. github-actions commented on Aug 18, 2021

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

  12. locked as resolved and limited conversation to collaborators on Aug 18, 2021
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

    p: pigeonrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions