Restore checks for leaf elements in ErrorVerifier.
We still need to check static types of leaf elements.
But constants might report additional errors using actual value types.
This fixes regressed:
co19_2/LanguageFeatures/Control-flow-collections/static_semantics_A01_t02/09
co19_2/LanguageFeatures/Control-flow-collections/static_semantics_A01_t02/11
R=brianwilkerson@google.com
Change-Id: Id3a6f650507f4b51028ccbde914da9fae836ed03
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97000
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 8bd952c..8dc85c4 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -3934,9 +3934,6 @@
* [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE].
*/
void _checkForListElementTypeNotAssignable(ListLiteral literal) {
- // Constants are verified using their actual values.
- if (literal.isConst) return;
-
// Determine the list's element type. We base this on the static type and
// not the literal's type arguments because in strong mode, the type
// arguments may be inferred.
@@ -5232,9 +5229,6 @@
* [StaticWarningCode.SET_ELEMENT_TYPE_NOT_ASSIGNABLE].
*/
void _checkForSetElementTypeNotAssignable3(SetOrMapLiteral literal) {
- // Constants are verified using their actual values.
- if (literal.isConst) return;
-
// Determine the set's element type. We base this on the static type and
// not the literal's type arguments because in strong mode, the type
// arguments may be inferred.
diff --git a/pkg/analyzer/test/src/diagnostics/list_element_type_not_assignable_test.dart b/pkg/analyzer/test/src/diagnostics/list_element_type_not_assignable_test.dart
index 4d3cc5f..0c27dc1 100644
--- a/pkg/analyzer/test/src/diagnostics/list_element_type_not_assignable_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/list_element_type_not_assignable_test.dart
@@ -68,6 +68,12 @@
}
test_const_ifElement_thenFalse_intString() async {
+ await assertErrorsInCode('''
+var v = const <int>[if (1 < 0) 'a'];
+''', [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE]);
+ }
+
+ test_const_ifElement_thenFalse_intString_dynamic() async {
await assertNoErrorsInCode('''
const dynamic a = 'a';
var v = const <int>[if (1 < 0) a];
@@ -110,6 +116,12 @@
''');
}
+ test_nonConst_ifElement_thenFalse_intString() async {
+ await assertErrorsInCode('''
+var v = <int>[if (1 < 0) 'a'];
+''', [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE]);
+ }
+
test_nonConst_ifElement_thenTrue_intDynamic() async {
await assertNoErrorsInCode('''
const dynamic a = 'a';
diff --git a/pkg/analyzer/test/src/diagnostics/set_element_type_not_assignable_test.dart b/pkg/analyzer/test/src/diagnostics/set_element_type_not_assignable_test.dart
index 54f9514..585a462 100644
--- a/pkg/analyzer/test/src/diagnostics/set_element_type_not_assignable_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/set_element_type_not_assignable_test.dart
@@ -69,6 +69,12 @@
}
test_const_ifElement_thenFalse_intString() async {
+ await assertErrorsInCode('''
+var v = const <int>{if (1 < 0) 'a'};
+''', [StaticWarningCode.SET_ELEMENT_TYPE_NOT_ASSIGNABLE]);
+ }
+
+ test_const_ifElement_thenFalse_intString_dynamic() async {
await assertNoErrorsInCode('''
const dynamic a = 'a';
var v = const <int>{if (1 < 0) a};
@@ -111,6 +117,12 @@
''');
}
+ test_nonConst_ifElement_thenFalse_intString() async {
+ await assertErrorsInCode('''
+var v = <int>[if (1 < 0) 'a'];
+''', [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE]);
+ }
+
test_nonConst_ifElement_thenTrue_intDynamic() async {
await assertNoErrorsInCode('''
const dynamic a = 'a';