Skip to content

Commit 15be61e

Browse files
committed
Remove INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES warnings
Fixes #49112 It was decided to remove the "override with equal default value" restriction both for null safe code, and for pre-null safe code. CFE had never issued this static warning, and her we remove it from analyzer. Change-Id: I1244e4fe46da8bb4bd8c3a77ec8beb95811e30a1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262267 Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 33c1ff6 commit 15be61e

File tree

9 files changed

+2
-899
lines changed

9 files changed

+2
-899
lines changed

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# - 206 for ParserErrorCodes.
2929
# - 68 "needsFix"
3030
# - 287 "hasFix"
31-
# - 57 "noFix"
31+
# - 55 "noFix"
3232

3333
AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR:
3434
status: noFix
@@ -2599,14 +2599,6 @@ StaticWarningCode.INVALID_NULL_AWARE_OPERATOR:
25992599
status: hasFix
26002600
StaticWarningCode.INVALID_NULL_AWARE_OPERATOR_AFTER_SHORT_CIRCUIT:
26012601
status: hasFix
2602-
StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED:
2603-
status: noFix
2604-
notes: |-
2605-
This is a pre-null safety code. No need to add a fix.
2606-
StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL:
2607-
status: noFix
2608-
notes: |-
2609-
This is a pre-null safety code. No need to add a fix.
26102602
StaticWarningCode.MISSING_ENUM_CONSTANT_IN_SWITCH:
26112603
status: hasFix
26122604
StaticWarningCode.UNNECESSARY_NON_NULL_ASSERTION:

pkg/analyzer/lib/error/error.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -953,8 +953,6 @@ const List<ErrorCode> errorCodeValues = [
953953
StaticWarningCode.DEAD_NULL_AWARE_EXPRESSION,
954954
StaticWarningCode.INVALID_NULL_AWARE_OPERATOR,
955955
StaticWarningCode.INVALID_NULL_AWARE_OPERATOR_AFTER_SHORT_CIRCUIT,
956-
StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED,
957-
StaticWarningCode.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL,
958956
StaticWarningCode.MISSING_ENUM_CONSTANT_IN_SWITCH,
959957
StaticWarningCode.UNNECESSARY_NON_NULL_ASSERTION,
960958
TodoCode.TODO,

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

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5213,40 +5213,6 @@ class StaticWarningCode extends AnalyzerErrorCode {
52135213
uniqueName: 'INVALID_NULL_AWARE_OPERATOR_AFTER_SHORT_CIRCUIT',
52145214
);
52155215

5216-
/// 7.1 Instance Methods: It is a static warning if an instance method
5217-
/// <i>m1</i> overrides an instance member <i>m2</i>, the signature of
5218-
/// <i>m2</i> explicitly specifies a default value for a formal parameter
5219-
/// <i>p</i> and the signature of <i>m1</i> specifies a different default value
5220-
/// for <i>p</i>.
5221-
///
5222-
/// Parameters:
5223-
/// 0: the name of the super class
5224-
/// 1: the name of the super method
5225-
/// 2: the name of the overriding method
5226-
static const StaticWarningCode
5227-
INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED = StaticWarningCode(
5228-
'INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED',
5229-
"Parameters can't override default values, this method overrides '{0}.{1}' "
5230-
"where '{2}' has a different value.",
5231-
correctionMessage: "Try using the same default value in both methods.",
5232-
);
5233-
5234-
/// 7.1 Instance Methods: It is a static warning if an instance method
5235-
/// <i>m1</i> overrides an instance member <i>m2</i>, the signature of
5236-
/// <i>m2</i> explicitly specifies a default value for a formal parameter
5237-
/// <i>p</i> and the signature of <i>m1</i> specifies a different default value
5238-
/// for <i>p</i>.
5239-
/// Parameters:
5240-
/// 0: the name of the super class
5241-
/// 1: the name of the super method
5242-
static const StaticWarningCode
5243-
INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL = StaticWarningCode(
5244-
'INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL',
5245-
"Parameters can't override default values, this method overrides '{0}.{1}' "
5246-
"where this positional parameter has a different value.",
5247-
correctionMessage: "Try using the same default value in both methods.",
5248-
);
5249-
52505216
/// Parameters:
52515217
/// 0: the name of the constant that is missing
52525218
static const StaticWarningCode MISSING_ENUM_CONSTANT_IN_SWITCH =

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

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'package:analyzer/dart/analysis/features.dart';
66
import 'package:analyzer/dart/ast/ast.dart';
77
import 'package:analyzer/dart/ast/syntactic_entity.dart';
88
import 'package:analyzer/dart/ast/token.dart';
9-
import 'package:analyzer/dart/constant/value.dart';
109
import 'package:analyzer/dart/element/element.dart';
1110
import 'package:analyzer/dart/element/type.dart';
1211
import 'package:analyzer/dart/element/type_provider.dart';
@@ -355,17 +354,6 @@ class _ClassVerifier {
355354
errorReporter: reporter,
356355
errorNode: node,
357356
);
358-
359-
if (!_isNonNullableByDefault &&
360-
superMember is MethodElement &&
361-
member is MethodElement &&
362-
methodParameterNodes != null) {
363-
_checkForOptionalParametersDifferentDefaultValues(
364-
superMember,
365-
member,
366-
methodParameterNodes,
367-
);
368-
}
369357
}
370358

371359
if (mixinIndex == -1) {
@@ -504,98 +492,6 @@ class _ClassVerifier {
504492
return true;
505493
}
506494

507-
void _checkForOptionalParametersDifferentDefaultValues(
508-
MethodElement baseExecutable,
509-
MethodElement derivedExecutable,
510-
List<FormalParameter> derivedParameterNodes,
511-
) {
512-
var derivedIsAbstract = derivedExecutable.isAbstract;
513-
var derivedOptionalNodes = <FormalParameter>[];
514-
var derivedOptionalElements = <ParameterElementImpl>[];
515-
var derivedParameterElements = derivedExecutable.parameters;
516-
for (var i = 0; i < derivedParameterElements.length; i++) {
517-
var parameterElement =
518-
derivedParameterElements[i] as ParameterElementImpl;
519-
if (parameterElement.isOptional) {
520-
derivedOptionalNodes.add(derivedParameterNodes[i]);
521-
derivedOptionalElements.add(parameterElement);
522-
}
523-
}
524-
525-
var baseOptionalElements = <ParameterElementImpl>[];
526-
var baseParameterElements = baseExecutable.parameters;
527-
for (var i = 0; i < baseParameterElements.length; ++i) {
528-
var baseParameter = baseParameterElements[i];
529-
if (baseParameter.isOptional) {
530-
baseOptionalElements
531-
.add(baseParameter.declaration as ParameterElementImpl);
532-
}
533-
}
534-
535-
// Stop if no optional parameters.
536-
if (baseOptionalElements.isEmpty || derivedOptionalElements.isEmpty) {
537-
return;
538-
}
539-
540-
if (derivedOptionalElements[0].isNamed) {
541-
for (int i = 0; i < derivedOptionalElements.length; i++) {
542-
var derivedElement = derivedOptionalElements[i];
543-
if (_isNonNullableByDefault &&
544-
derivedIsAbstract &&
545-
!derivedElement.hasDefaultValue) {
546-
continue;
547-
}
548-
var name = derivedElement.name;
549-
for (var j = 0; j < baseOptionalElements.length; j++) {
550-
var baseParameter = baseOptionalElements[j];
551-
if (name == baseParameter.name && baseParameter.hasDefaultValue) {
552-
var baseValue = baseParameter.computeConstantValue();
553-
var derivedResult = derivedElement.evaluationResult!;
554-
if (!_constantValuesEqual(derivedResult.value, baseValue)) {
555-
reporter.reportErrorForNode(
556-
StaticWarningCode
557-
.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED,
558-
derivedOptionalNodes[i],
559-
[
560-
baseExecutable.enclosingElement.displayName,
561-
baseExecutable.displayName,
562-
name
563-
],
564-
);
565-
}
566-
}
567-
}
568-
}
569-
} else {
570-
for (var i = 0;
571-
i < derivedOptionalElements.length && i < baseOptionalElements.length;
572-
i++) {
573-
var derivedElement = derivedOptionalElements[i];
574-
if (_isNonNullableByDefault &&
575-
derivedIsAbstract &&
576-
!derivedElement.hasDefaultValue) {
577-
continue;
578-
}
579-
var baseElement = baseOptionalElements[i];
580-
if (baseElement.hasDefaultValue) {
581-
var baseValue = baseElement.computeConstantValue();
582-
var derivedResult = derivedElement.evaluationResult!;
583-
if (!_constantValuesEqual(derivedResult.value, baseValue)) {
584-
reporter.reportErrorForNode(
585-
StaticWarningCode
586-
.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL,
587-
derivedOptionalNodes[i],
588-
[
589-
baseExecutable.enclosingElement.displayName,
590-
baseExecutable.displayName
591-
],
592-
);
593-
}
594-
}
595-
}
596-
}
597-
}
598-
599495
/// Check that [classElement] is not a superinterface to itself.
600496
/// The [path] is a list containing the potentially cyclic implements path.
601497
///
@@ -1030,12 +926,4 @@ class _ClassVerifier {
1030926
);
1031927
}
1032928
}
1033-
1034-
static bool _constantValuesEqual(DartObject? x, DartObject? y) {
1035-
// If either constant value couldn't be computed due to an error, the
1036-
// corresponding DartObject will be `null`. Since an error has already been
1037-
// reported, there's no need to report another.
1038-
if (x == null || y == null) return true;
1039-
return x == y;
1040-
}
1041929
}

pkg/analyzer/messages.yaml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22816,32 +22816,6 @@ StaticWarningCode:
2281622816
Parameters:
2281722817
0: the null-aware operator that is invalid
2281822818
1: the non-null-aware operator that can replace the invalid operator
22819-
INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_NAMED:
22820-
problemMessage: "Parameters can't override default values, this method overrides '{0}.{1}' where '{2}' has a different value."
22821-
correctionMessage: Try using the same default value in both methods.
22822-
comment: |-
22823-
7.1 Instance Methods: It is a static warning if an instance method
22824-
<i>m1</i> overrides an instance member <i>m2</i>, the signature of
22825-
<i>m2</i> explicitly specifies a default value for a formal parameter
22826-
<i>p</i> and the signature of <i>m1</i> specifies a different default value
22827-
for <i>p</i>.
22828-
22829-
Parameters:
22830-
0: the name of the super class
22831-
1: the name of the super method
22832-
2: the name of the overriding method
22833-
INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES_POSITIONAL:
22834-
problemMessage: "Parameters can't override default values, this method overrides '{0}.{1}' where this positional parameter has a different value."
22835-
correctionMessage: Try using the same default value in both methods.
22836-
comment: |-
22837-
7.1 Instance Methods: It is a static warning if an instance method
22838-
<i>m1</i> overrides an instance member <i>m2</i>, the signature of
22839-
<i>m2</i> explicitly specifies a default value for a formal parameter
22840-
<i>p</i> and the signature of <i>m1</i> specifies a different default value
22841-
for <i>p</i>.
22842-
Parameters:
22843-
0: the name of the super class
22844-
1: the name of the super method
2284522819
MISSING_ENUM_CONSTANT_IN_SWITCH:
2284622820
problemMessage: "Missing case clause for '{0}'."
2284722821
correctionMessage: Try adding a case clause for the missing constant, or adding a default clause.

0 commit comments

Comments
 (0)