-
Notifications
You must be signed in to change notification settings - Fork 1.7k
proposal: avoid_nullable_equals_parameter
#58753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This could perhaps supersede If I understand correctly that lint only fires when the argument is nullable. |
There is one place where using Example: class C<T> {
bool checkStuff(T other) => true;
@override
bool operator ==(Object other) => other is T && checkStuff(other);
// ^^^^^
// The argument type 'Object' can't be assigned to the parameter type 'T'.
} I think it's probably better to find a different pattern for the body than to widen the argument type to get promotion. |
Could also flag no argument |
+100. One question:
Does this fact come from spec? Or just existing behavior of today's backends? |
It's from the spec (the third bullet item):
|
Some flutter customer tests violate this so the change is being reverted. #51038 |
Make operator == override parameters no-nullable. See https://github.com/dart-lang/linter/issues/3441 Work towards dart-lang/sdk#51038.
Make operator == override parameters no-nullable. See dart-lang/linter#3441 Work towards dart-lang/sdk#51038.
…r#3441 Work towards dart-lang/sdk#51038.
This prepares for the new [`NON_NULLABLE_EQUALS_PARAMETER`](osa1/sdk@48ee1f2) diagnostic discussed in https://github.com/dart-lang/linter/issues/3441.
* == override parameters are non-nullable Make operator == override parameters no-nullable. See dart-lang/linter#3441 Work towards dart-lang/sdk#51038. * Update fake_google_account.dart
* Make operator == override parameters no-nullable. See dart-lang/linter#3441 Work towards dart-lang/sdk#51038.
* Make operator == override parameters no-nullable. See dart-lang/linter#3441 Work towards dart-lang/sdk#51038.
…pe"" This reverts commit 885457e. [analyzer] new warning for nullable '==' parameter type This rule checks that a parameter to an `operator ==` implementation has a non-nullable type. I intentionally did not enforce, in this rule, that the parameter is exactly `Object`. It is legal to narrow the parameter type to a different non-nullable type, like `int`. I can't imagine doing it, but it seems to be unrelated to whether the type should be nullable or not. Fixes https://github.com/dart-lang/linter/issues/3441 Replaces dart-archive/linter#3923 Change-Id: Ic0be2bfebaf59b0336e9a3a58e5b7f5359eb8646 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291042 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Stephen Adams <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
Wasn't this solved by https://dart-review.googlesource.com/c/sdk/+/277700? |
Description
"The null value will never be passed to
operator ==
. Use a non-nullableObject
parameter"Details
A definition like
bool operator ==(Object? other)
causes other classes which override the interface to also accept a nullable argument, even thoughnull
will never be passed.Kind
Style
Good Examples
Bad Examples
Discussion
Mockito codegen currently fails to generate fakes for classes with a nullable argument to
operator ==
.The main motivator is that the code is misleading -
null
can't show up so it's not worth making it look like it can.The text was updated successfully, but these errors were encountered: