Skip to content

Commit 885457e

Browse files
Kaushik IskaCommit Queue
authored andcommitted
Revert "[analyzer] new warning for nullable '==' parameter type"
This reverts commit 48ee1f2. Reason for revert: flutter/flutter#118632 Original change's description: > [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: I61d4a7b1ab8318dc9403da1633c352de95bfac61 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/277700 > Reviewed-by: Mark Zhou <[email protected]> > Commit-Queue: Samuel Rawlins <[email protected]> > Reviewed-by: Brian Wilkerson <[email protected]> # Not skipping CQ checks because original CL landed > 1 day ago. Change-Id: I6f96936b8d4e785b5f8e9719751e4b61c2a6ca2a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279141 Reviewed-by: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Siva Annamalai <[email protected]> Reviewed-by: Mark Zhou <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent 3ee9c0b commit 885457e

File tree

14 files changed

+21
-179
lines changed

14 files changed

+21
-179
lines changed

pkg/_fe_analyzer_shared/lib/src/parser/identifier_context_impl.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ class ExtensionShowHideElementIdentifierContext extends IdentifierContext {
447447
}
448448

449449
@override
450-
bool operator ==(Object other) {
450+
bool operator ==(dynamic other) {
451451
return other is ExtensionShowHideElementIdentifierContext &&
452452
_kind == other._kind;
453453
}

pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# - 655 "needsEvaluation"
2828
# - 282 for CompileTimeErrorCodes
2929
# - 220 for ParserErrorCodes
30-
# - 93 "needsFix"
30+
# - 92 "needsFix"
3131
# - 310 "hasFix"
3232
# - 94 "noFix"
3333

@@ -2755,11 +2755,6 @@ StaticWarningCode.INVALID_NULL_AWARE_OPERATOR_AFTER_SHORT_CIRCUIT:
27552755
status: hasFix
27562756
StaticWarningCode.MISSING_ENUM_CONSTANT_IN_SWITCH:
27572757
status: hasFix
2758-
StaticWarningCode.NON_NULLABLE_EQUALS_PARAMETER:
2759-
status: needsFix
2760-
notes: |-
2761-
The fix is to remove the question mark if the parameter has one (if the
2762-
written type is an alias, it may not).
27632758
StaticWarningCode.SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT:
27642759
status: hasFix
27652760
StaticWarningCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE:

pkg/analysis_server/test/src/services/correction/fix/remove_comparison_test.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ class Person {
281281
final String name = '';
282282
283283
@override
284-
operator ==(Object other) =>
284+
operator ==(Object? other) =>
285285
other != null &&
286286
other is Person &&
287287
name == other.name;
@@ -292,7 +292,7 @@ class Person {
292292
final String name = '';
293293
294294
@override
295-
operator ==(Object other) =>
295+
operator ==(Object? other) =>
296296
other is Person &&
297297
name == other.name;
298298
}
@@ -305,7 +305,7 @@ class Person {
305305
final String name = '';
306306
307307
@override
308-
operator ==(Object other) {
308+
operator ==(Object? other) {
309309
return other != null &&
310310
other is Person &&
311311
name == other.name;
@@ -317,7 +317,7 @@ class Person {
317317
final String name = '';
318318
319319
@override
320-
operator ==(Object other) {
320+
operator ==(Object? other) {
321321
return other is Person &&
322322
name == other.name;
323323
}
@@ -331,7 +331,7 @@ class Person {
331331
final String name = '';
332332
333333
@override
334-
operator ==(Object other) {
334+
operator ==(Object? other) {
335335
if (other is! Person) return false;
336336
other ??= Person();
337337
return other.name == name;
@@ -349,7 +349,7 @@ class Person {
349349
final String name = '';
350350
351351
@override
352-
operator ==(Object other) {
352+
operator ==(Object? other) {
353353
if (other is! Person) return false;
354354
final toCompare = other ?? Person();
355355
return toCompare.name == name;
@@ -362,7 +362,7 @@ class Person {
362362
final String name = '';
363363
364364
@override
365-
operator ==(Object other) {
365+
operator ==(Object? other) {
366366
if (other is! Person) return false;
367367
final toCompare = other;
368368
return toCompare.name == name;
@@ -381,7 +381,7 @@ class Person {
381381
final String name = '';
382382
383383
@override
384-
operator ==(Object other) {
384+
operator ==(Object? other) {
385385
if (other == null) return false;
386386
return other is Person &&
387387
name == other.name;
@@ -393,7 +393,7 @@ class Person {
393393
final String name = '';
394394
395395
@override
396-
operator ==(Object other) {
396+
operator ==(Object? other) {
397397
return other is Person &&
398398
name == other.name;
399399
}

pkg/analysis_server/tool/code_completion/metrics_util.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ class Place {
458458
int get rank => _numerator;
459459

460460
@override
461-
bool operator ==(Object other) =>
461+
bool operator ==(dynamic other) =>
462462
other is Place &&
463463
_numerator == other._numerator &&
464464
_denominator == other._denominator;

pkg/analyzer/lib/src/error/best_practices_verifier.dart

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,6 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
683683
_checkForMissingReturn(node.body, node);
684684
_mustCallSuperVerifier.checkMethodDeclaration(node);
685685
_checkForUnnecessaryNoSuchMethod(node);
686-
_checkForNullableEqualsParameterType(node);
687686

688687
var name = Name(_currentLibrary.source.uri, element.name);
689688
var elementIsOverride = element is ClassMemberElement &&
@@ -1391,44 +1390,6 @@ class BestPracticesVerifier extends RecursiveAstVisitor<void> {
13911390
}
13921391
}
13931392

1394-
void _checkForNullableEqualsParameterType(MethodDeclaration node) {
1395-
if (!_typeSystem.isNonNullableByDefault) {
1396-
// Cannot specify non-nullable types before null safety.
1397-
return;
1398-
}
1399-
1400-
if (node.name.type != TokenType.EQ_EQ) {
1401-
return;
1402-
}
1403-
1404-
var parameters = node.parameters;
1405-
if (parameters == null) {
1406-
return;
1407-
}
1408-
1409-
if (parameters.parameters.length != 1) {
1410-
return;
1411-
}
1412-
1413-
var parameter = parameters.parameters.first;
1414-
var parameterElement = parameter.declaredElement;
1415-
if (parameterElement == null) {
1416-
return;
1417-
}
1418-
1419-
var type = parameterElement.type;
1420-
if (!type.isDartCoreObject && !type.isDynamic) {
1421-
// There is no legal way to define a nullable parameter type, which is not
1422-
// `dynamic` or `Object?`, so avoid double reporting here.
1423-
return;
1424-
}
1425-
1426-
if (_typeSystem.isNullable(parameterElement.type)) {
1427-
_errorReporter.reportErrorForToken(
1428-
StaticWarningCode.NON_NULLABLE_EQUALS_PARAMETER, node.name);
1429-
}
1430-
}
1431-
14321393
void _checkForNullableTypeInCatchClause(CatchClause node) {
14331394
if (!_isNonNullableByDefault) {
14341395
return;

pkg/analyzer/lib/src/error/codes.g.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5645,14 +5645,6 @@ class StaticWarningCode extends AnalyzerErrorCode {
56455645
hasPublishedDocs: true,
56465646
);
56475647

5648-
/// No parameters.
5649-
static const StaticWarningCode NON_NULLABLE_EQUALS_PARAMETER =
5650-
StaticWarningCode(
5651-
'NON_NULLABLE_EQUALS_PARAMETER',
5652-
"The parameter type of '==' operators should be non-nullable.",
5653-
correctionMessage: "Try using a non-nullable type.",
5654-
);
5655-
56565648
/// Parameters:
56575649
/// 0: the name of the class
56585650
static const StaticWarningCode SDK_VERSION_ASYNC_EXPORTED_FROM_CORE =

pkg/analyzer/lib/src/error/error_code_values.g.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,6 @@ const List<ErrorCode> errorCodeValues = [
965965
StaticWarningCode.INVALID_NULL_AWARE_OPERATOR,
966966
StaticWarningCode.INVALID_NULL_AWARE_OPERATOR_AFTER_SHORT_CIRCUIT,
967967
StaticWarningCode.MISSING_ENUM_CONSTANT_IN_SWITCH,
968-
StaticWarningCode.NON_NULLABLE_EQUALS_PARAMETER,
969968
StaticWarningCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE,
970969
StaticWarningCode.SDK_VERSION_AS_EXPRESSION_IN_CONST_CONTEXT,
971970
StaticWarningCode.SDK_VERSION_BOOL_OPERATOR_IN_CONST_CONTEXT,

pkg/analyzer/messages.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5643,7 +5643,7 @@ CompileTimeErrorCode:
56435643

56445644
```dart
56455645
mixin M on Enum {
5646-
bool operator [!==!](Object other) => false;
5646+
bool operator [!==!](Object? other) => false;
56475647
}
56485648
```
56495649

@@ -22797,11 +22797,6 @@ StaticWarningCode:
2279722797
```
2279822798
TODO(brianwilkerson) This documentation will need to be updated when NNBD
2279922799
ships.
22800-
NON_NULLABLE_EQUALS_PARAMETER:
22801-
problemMessage: "The parameter type of '==' operators should be non-nullable."
22802-
correctionMessage: Try using a non-nullable type.
22803-
hasPublishedDocs: false
22804-
comment: No parameters.
2280522800
SDK_VERSION_ASYNC_EXPORTED_FROM_CORE:
2280622801
problemMessage: "The class '{0}' wasn't exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions."
2280722802
correctionMessage: "Try either importing 'dart:async' or updating the SDK constraints."

pkg/analyzer/test/src/diagnostics/extension_declares_member_of_object_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ extension E on String {
2828
test_instance_sameKind() async {
2929
await assertErrorsInCode('''
3030
extension E on String {
31-
bool operator==(Object _) => false;
31+
bool operator==(_) => false;
3232
int get hashCode => 0;
3333
String toString() => '';
3434
dynamic get runtimeType => null;
3535
dynamic noSuchMethod(_) => null;
3636
}
3737
''', [
3838
error(CompileTimeErrorCode.EXTENSION_DECLARES_MEMBER_OF_OBJECT, 39, 2),
39-
error(CompileTimeErrorCode.EXTENSION_DECLARES_MEMBER_OF_OBJECT, 72, 8),
40-
error(CompileTimeErrorCode.EXTENSION_DECLARES_MEMBER_OF_OBJECT, 96, 8),
41-
error(CompileTimeErrorCode.EXTENSION_DECLARES_MEMBER_OF_OBJECT, 128, 11),
42-
error(CompileTimeErrorCode.EXTENSION_DECLARES_MEMBER_OF_OBJECT, 159, 12),
39+
error(CompileTimeErrorCode.EXTENSION_DECLARES_MEMBER_OF_OBJECT, 65, 8),
40+
error(CompileTimeErrorCode.EXTENSION_DECLARES_MEMBER_OF_OBJECT, 89, 8),
41+
error(CompileTimeErrorCode.EXTENSION_DECLARES_MEMBER_OF_OBJECT, 121, 11),
42+
error(CompileTimeErrorCode.EXTENSION_DECLARES_MEMBER_OF_OBJECT, 152, 12),
4343
]);
4444
}
4545

pkg/analyzer/test/src/diagnostics/non_nullable_equals_parameter_test.dart

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)