Report DEFAULT_LIST_CONSTRUCTOR_MISMATCH only in opt-in libraries.
R=brianwilkerson@google.com
Change-Id: I8c2a0e6742af85c00db04a5a7a94f3b91b9cee13
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106964
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index 9a91f60..2d8ea10 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -4026,6 +4026,8 @@
void _checkForListConstructor(
InstanceCreationExpression node, InterfaceType type) {
+ if (!_isNonNullable) return;
+
if (node.argumentList.arguments.length == 1 &&
_isDartCoreList(type) &&
_typeSystem.isPotentiallyNonNullable(type.typeArguments[0])) {
diff --git a/pkg/analyzer/test/src/diagnostics/default_list_constructor_mismatch_test.dart b/pkg/analyzer/test/src/diagnostics/default_list_constructor_mismatch_test.dart
index 30e9267..c47a2fd 100644
--- a/pkg/analyzer/test/src/diagnostics/default_list_constructor_mismatch_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/default_list_constructor_mismatch_test.dart
@@ -22,6 +22,15 @@
..contextFeatures = new FeatureSet.forTesting(
sdkVersion: '2.3.0', additionalFeatures: [Feature.non_nullable]);
+ test_inferredType() async {
+ await assertErrorsInCode('''
+class C {}
+List<C> v = List(5);
+''', [
+ error(CompileTimeErrorCode.DEFAULT_LIST_CONSTRUCTOR_MISMATCH, 23, 4),
+ ]);
+ }
+
test_nonNullableType() async {
await assertErrorsInCode('''
var l = new List<int>(3);
@@ -36,13 +45,11 @@
''');
}
- test_inferredType() async {
- await assertErrorsInCode('''
-class C {}
-List<C> v = List(5);
-''', [
- error(CompileTimeErrorCode.DEFAULT_LIST_CONSTRUCTOR_MISMATCH, 23, 4),
- ]);
+ test_optOut() async {
+ await assertNoErrorsInCode('''
+// @dart = 2.2
+var l = new List<int>(3);
+''');
}
test_typeParameter() async {