linter icon indicating copy to clipboard operation
linter copied to clipboard

False positive for `avoid_redundant_argument_values`

Open kuhnroyal opened this issue 3 years ago • 5 comments

Describe the issue After the update to Dart 2.15, I have some false warnings for generated copy code. I boiled it down to a small sample.

In the sample below in foo1.copyWith(a: null) the null is marked as redundant because the parameter type is String? a. But actual overridden implementation has a default value String? a = _absent.

Not sure if this is not found because of the factory delegation.

To Reproduce

void main() {
  final foo1 = Foo(a: 'test',b: 2);
  final foo2 = foo1.copyWith(a: null);


  print(foo1);
  print(foo2);
}

abstract class Foo {
  factory Foo({
    required String? a,
    required int? b,
  }) = FooImpl;

  Foo copyWith({String? a, int? b});
}


class FooImpl implements Foo {
  static const Object _absent = Object();

  final String? a;

  final int? b;

  FooImpl({
    required this.a,
    required this.b,
  });

  @override
  Foo copyWith({Object? a = _absent, Object? b= _absent,}) {
    return FooImpl(
      a: a == _absent ? this.a : a as String?,
      b: b == _absent ? this.b : b as int?,
    );
  }
}

Expected behavior I don't expect a warning in this case.

kuhnroyal avatar Dec 13 '21 09:12 kuhnroyal