google/protobuf.dart

Error "The named parameter 'valueDefaultOrMaker' isn't defined." in version 21.1.2 (protoc 26.1)

philer-jambit opened this issue · 3 comments

When I compile the following protobuf I get invalid dart code:

syntax = "proto3";

package example;

message Inner {
  string bar = 1;
}

message Outer {
  map<string, Inner> entries = 1;
}

The generated code contains this block:

class Outer extends $pb.GeneratedMessage {
  // ...

  static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'Outer', package: const $pb.PackageName(_omitMessageNames ? '' : 'example'), createEmptyInstance: create)
    ..m<$core.String, Inner>(1, _omitFieldNames ? '' : 'entries', entryClassName: 'Outer.EntriesEntry', keyFieldType: $pb.PbFieldType.OS, valueFieldType: $pb.PbFieldType.OM, valueCreator: Inner.create, valueDefaultOrMaker: Inner.getDefault, packageName: const $pb.PackageName('example'))
    ..hasRequiredFields = false
  ;

Full file: example.pb.dart.txt

The argument valueDefaultOrMaker is noted as an error by dart: The named parameter 'valueDefaultOrMaker' isn't defined.

This was previously reported in #786. At the time it was noted that the user was probably on a not yet released version – however the bug (presumably?) has since been released.

Please let me know if there is anything else I should try or do to help.


dart protoc_plugin installed via dart pub global activate protoc_plugin: 21.1.2
protoc downloaded from https://github.com/protocolbuffers/protobuf/releases/tag/v26.1

osa1 commented

Make sure you are using the latest version of protobuf (3.1.0), and run dart pub get. The named parameter is defined https://pub.dev/documentation/protobuf/latest/protobuf/BuilderInfo/m.html (search for valueDefaultOrMaker) so you probably have a problem with your setup.

It turns out we are still on v2 (I was a bit confused about the distinct versions for the protobuf compiler and support library) due to a dependency. So now we are stuck here: PhilipsHue/flutter_reactive_ble#785

Since that is outside of your domain I guess this issue can be closed. Thank you for your support! :)

In case anyone else gets stuck in the same place: As a workaround we're currently just removing the offending parameter.

find -name "*.pb.dart" | xargs sed -i 's/valueDefaultOrMaker: [[:alnum:]]\+\.getDefault,//g'