Skip to content

Commit 6c9b885

Browse files
committed
Remove StrongModeCode.INVALID_PARAMETER_DECLARATION; it's redundant
You can see in the included test that we already report `FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE`. Change-Id: Ib7c4177627120a31910d3929d61f5337cb869b1d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/155281 Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
1 parent b98eb38 commit 6c9b885

File tree

13 files changed

+18
-40
lines changed

13 files changed

+18
-40
lines changed

pkg/analyzer/lib/error/error.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,6 @@ const List<ErrorCode> errorCodeValues = [
838838
StrongModeCode.IMPLICIT_DYNAMIC_RETURN,
839839
StrongModeCode.IMPLICIT_DYNAMIC_TYPE,
840840
StrongModeCode.IMPLICIT_DYNAMIC_VARIABLE,
841-
StrongModeCode.INVALID_PARAMETER_DECLARATION,
842841
StrongModeCode.TOP_LEVEL_CYCLE,
843842
StrongModeCode.TOP_LEVEL_FUNCTION_LITERAL_BLOCK,
844843
StrongModeCode.TOP_LEVEL_IDENTIFIER_NO_TYPE,

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10781,11 +10781,6 @@ class StrongModeCode extends ErrorCode {
1078110781
"Try adding an explicit type like 'dynamic', or "
1078210782
"enable implicit-dynamic in your analysis options file.";
1078310783

10784-
static const StrongModeCode INVALID_PARAMETER_DECLARATION = StrongModeCode(
10785-
ErrorType.COMPILE_TIME_ERROR,
10786-
'INVALID_PARAMETER_DECLARATION',
10787-
"Type check failed: '{0}' isn't of type '{1}'.");
10788-
1078910784
static const StrongModeCode COULD_NOT_INFER = StrongModeCode(
1079010785
ErrorType.COMPILE_TIME_ERROR,
1079110786
'COULD_NOT_INFER',

pkg/analyzer/lib/src/generated/error_verifier.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4366,7 +4366,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void> {
43664366
[parameter.identifier.name]);
43674367
} else if (declaredType != null &&
43684368
fieldType != null &&
4369-
!_typeSystem.isAssignableTo2(declaredType, fieldType)) {
4369+
!_typeSystem.isSubtypeOf(declaredType, fieldType)) {
43704370
_errorReporter.reportErrorForNode(
43714371
StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE,
43724372
parameter,

pkg/analyzer/lib/src/task/strong/checker.dart

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -352,23 +352,6 @@ class CodeChecker extends RecursiveAstVisitor {
352352
node.visitChildren(this);
353353
}
354354

355-
@override
356-
void visitFieldFormalParameter(FieldFormalParameter node) {
357-
var element = node.declaredElement;
358-
var typeName = node.type;
359-
if (typeName != null) {
360-
var type = _elementType(element);
361-
var fieldElement =
362-
node.identifier.staticElement as FieldFormalParameterElement;
363-
var fieldType = _elementType(fieldElement.field);
364-
if (!rules.isSubtypeOf2(type, fieldType)) {
365-
_recordMessage(node, StrongModeCode.INVALID_PARAMETER_DECLARATION,
366-
[node, fieldType]);
367-
}
368-
}
369-
node.visitChildren(this);
370-
}
371-
372355
@override
373356
void visitForEachPartsWithDeclaration(ForEachPartsWithDeclaration node) {
374357
_visitForEachParts(node, node.loopVariable?.identifier);

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,24 @@ main() {
1515

1616
@reflectiveTest
1717
class FieldInitializingFormalNotAssignableTest extends DriverResolutionTest {
18+
test_dynamic() async {
19+
await assertErrorsInCode('''
20+
class A {
21+
int x;
22+
A(dynamic this.x) {}
23+
}
24+
''', [
25+
error(StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE, 23, 14),
26+
]);
27+
}
28+
1829
test_unrelated() async {
1930
await assertErrorsInCode('''
2031
class A {
2132
int x;
2233
A(String this.x) {}
2334
}
2435
''', [
25-
error(StrongModeCode.INVALID_PARAMETER_DECLARATION, 23, 13),
2636
error(StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE, 23, 13),
2737
]);
2838
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:analyzer/dart/element/element.dart';
66
import 'package:analyzer/src/dart/error/syntactic_errors.dart';
7+
import 'package:analyzer/src/error/codes.dart';
78
import 'package:test_reflective_loader/test_reflective_loader.dart';
89

910
import '../dart/resolution/driver_resolution.dart';
@@ -24,6 +25,8 @@ mixin M {
2425
}
2526
''', [
2627
error(ParserErrorCode.MIXIN_DECLARES_CONSTRUCTOR, 27, 1),
28+
// TODO(srawlins): Don't report this from within a mixin.
29+
error(StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE, 29, 6),
2730
]);
2831

2932
var element = findElement.mixin('M');

pkg/analyzer/test/src/task/strong/checker_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ class A {
422422
423423
A.c2(this.x, this.y);
424424
425-
A.c3(/*error:INVALID_PARAMETER_DECLARATION*/num this.x, String this.y);
425+
A.c3(/*error:FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE*/num this.x, String this.y);
426426
}
427427
428428
class B extends A {

tests/language/compile_time_constant/static2_test.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class A {
1717
// [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
1818
const A.a4(String this.x);
1919
// ^^^^^^^^^^^^^
20-
// [analyzer] COMPILE_TIME_ERROR.INVALID_PARAMETER_DECLARATION
21-
// ^^^^^^^^^^^^^
2220
// [analyzer] STATIC_WARNING.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE
2321
// ^
2422
// [cfe] The type of parameter 'x', 'String' is not a subtype of the corresponding field's type, 'int'.

tests/language/compile_time_constant/static3_test.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class A {
1717
// [cfe] A value of type 'String' can't be assigned to a variable of type 'int'.
1818
const A.a4(String this.x);
1919
// ^^^^^^^^^^^^^
20-
// [analyzer] COMPILE_TIME_ERROR.INVALID_PARAMETER_DECLARATION
21-
// ^^^^^^^^^^^^^
2220
// [analyzer] STATIC_WARNING.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE
2321
// ^
2422
// [cfe] The type of parameter 'x', 'String' is not a subtype of the corresponding field's type, 'int'.

tests/language/initializing_formal/type_annotation_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ class C {
1010
C.subType(int this.a);
1111
C.superType(dynamic this.a);
1212
// ^^^^^^^^^^^^^^
13-
// [analyzer] COMPILE_TIME_ERROR.INVALID_PARAMETER_DECLARATION
13+
// [analyzer] STATIC_WARNING.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE
1414
// ^
1515
// [cfe] The type of parameter 'a', 'dynamic' is not a subtype of the corresponding field's type, 'num'.
1616
C.unrelatedType(String this.a);
1717
// ^^^^^^^^^^^^^
18-
// [analyzer] COMPILE_TIME_ERROR.INVALID_PARAMETER_DECLARATION
19-
// ^^^^^^^^^^^^^
2018
// [analyzer] STATIC_WARNING.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE
2119
// ^
2220
// [cfe] The type of parameter 'a', 'String' is not a subtype of the corresponding field's type, 'num'.

0 commit comments

Comments
 (0)