google / built_value.dart

Immutable value types, enum classes, and serialization.
https://pub.dev/packages/built_value
BSD 3-Clause "New" or "Revised" License
862 stars 183 forks source link

SerializerBuilder / BuiltList - generated code contains duplicated builder factories #1160

Open danielgomezrico opened 2 years ago

danielgomezrico commented 2 years ago

Hi

If I have multiple models with a list of types or nullable types, it creates things like this:


// **************************************************************************
// BuiltValueGenerator
// **************************************************************************

Serializers _$serializers = ...
      ..addBuilderFactory(
          const FullType(BuiltList, const [const FullType(int)]),
          () => new ListBuilder<int>())
      ..addBuilderFactory(
          const FullType(BuiltList, const [const FullType(int)]),
          () => new ListBuilder<int>())
      ..addBuilderFactory(
          const FullType(BuiltList, const [const FullType(int)]),
       ..addBuilderFactory(
          const FullType(BuiltList, const [const FullType(String)]),
          () => new ListBuilder<String>())
      ..addBuilderFactory(
          const FullType(BuiltList, const [const FullType.nullable(int)]),
          () => new ListBuilder<int?>())
      ..addBuilderFactory(
          const FullType(BuiltList, const [const FullType.nullable(int)]),
          () => new ListBuilder<int?>())
      ..addBuilderFactory(
          const FullType(BuiltList, const [const FullType(String)]),
          () => new ListBuilder<String>())

If you check the BuiltList<String>, BuiltList<int?> and BuiltList<int> serializers are duplicated: image

Environment:

lookevink commented 1 year ago
Screen Shot 2022-10-03 at 4 08 28 PM

Same thing here @danielgomezrico

Wondering if deleting those lines caused any issues for you.

danielgomezrico commented 1 month ago

@lookevink It does not seem to be a big deal on runtime since the addBuilderFactory replace it and left the last one:

https://github.com/google/built_value.dart/blob/893244770a4f8a609f9a5be4335c29f27a29da63/built_value/lib/src/built_json_serializers.dart#L283-L290

davidmorgan commented 1 month ago

I seemed to have missed triaging this when it was filed, sorry about that.

Indeed, the extra lines should be harmless--except for a small code size and runtime cost. So, a minor bug.

I don't have a lot of bandwidth for built_value changes right now, so I expect it will be a while before I get to this, but it's on the backlog at least :) thanks!