@@ -846,8 +846,9 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
846
846
}
847
847
}
848
848
_checkForExpectedOneListTypeArgument (node, typeArguments);
849
- _checkForListElementTypeNotAssignable (node, typeArguments);
850
849
}
850
+
851
+ _checkForListElementTypeNotAssignable (node);
851
852
return super .visitListLiteral (node);
852
853
}
853
854
@@ -863,8 +864,9 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
863
864
}
864
865
}
865
866
_checkExpectedTwoMapTypeArguments (typeArguments);
866
- _checkForMapTypeNotAssignable (node, typeArguments);
867
867
}
868
+
869
+ _checkForMapTypeNotAssignable (node);
868
870
_checkForNonConstMapAsExpressionStatement (node);
869
871
return super .visitMapLiteral (node);
870
872
}
@@ -4038,91 +4040,81 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
4038
4040
}
4039
4041
4040
4042
/**
4041
- * Verify that the elements given list [literal] are subtypes of the specified
4042
- * element type. The [typeArguments] are the type arguments .
4043
+ * Verify that the elements given list [literal] are subtypes of the list's
4044
+ * static type.
4043
4045
*
4044
4046
* See [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE] , and
4045
4047
* [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE] .
4046
4048
*/
4047
- bool _checkForListElementTypeNotAssignable (
4048
- ListLiteral literal, TypeArgumentList typeArguments) {
4049
- NodeList <TypeName > typeNames = typeArguments.arguments;
4050
- if (typeNames.length < 1 ) {
4051
- return false ;
4052
- }
4053
- DartType listElementType = typeNames[0 ].type;
4049
+ void _checkForListElementTypeNotAssignable (ListLiteral literal) {
4050
+ // Determine the list's element type. We base this on the static type and
4051
+ // not the literal's type arguments because in strong mode, the type
4052
+ // arguments may be inferred.
4053
+ DartType listType = literal.staticType;
4054
+ assert (listType is InterfaceTypeImpl );
4055
+
4056
+ List <DartType > typeArguments =
4057
+ (listType as InterfaceTypeImpl ).typeArguments;
4058
+ assert (typeArguments.length == 1 );
4059
+
4060
+ DartType listElementType = typeArguments[0 ];
4061
+
4054
4062
// Check every list element.
4055
- bool hasProblems = false ;
4056
4063
for (Expression element in literal.elements) {
4057
4064
if (literal.constKeyword != null ) {
4058
4065
// TODO(paulberry): this error should be based on the actual type of the
4059
4066
// list element, not the static type. See dartbug.com/21119.
4060
- if ( _checkForArgumentTypeNotAssignableWithExpectedTypes (
4067
+ _checkForArgumentTypeNotAssignableWithExpectedTypes (
4061
4068
element,
4062
4069
listElementType,
4063
- CheckedModeCompileTimeErrorCode .LIST_ELEMENT_TYPE_NOT_ASSIGNABLE )) {
4064
- hasProblems = true ;
4065
- }
4066
- }
4067
- if (_checkForArgumentTypeNotAssignableWithExpectedTypes (
4068
- element,
4069
- listElementType,
4070
- StaticWarningCode .LIST_ELEMENT_TYPE_NOT_ASSIGNABLE )) {
4071
- hasProblems = true ;
4070
+ CheckedModeCompileTimeErrorCode .LIST_ELEMENT_TYPE_NOT_ASSIGNABLE );
4072
4071
}
4072
+ _checkForArgumentTypeNotAssignableWithExpectedTypes (element,
4073
+ listElementType, StaticWarningCode .LIST_ELEMENT_TYPE_NOT_ASSIGNABLE );
4073
4074
}
4074
- return hasProblems;
4075
4075
}
4076
4076
4077
4077
/**
4078
4078
* Verify that the key/value of entries of the given map [literal] are
4079
- * subtypes of the key/value types specified in the type arguments. The
4080
- * [typeArguments] are the type arguments.
4079
+ * subtypes of the map's static type.
4081
4080
*
4082
4081
* See [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE] ,
4083
4082
* [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE] ,
4084
4083
* [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE] , and
4085
4084
* [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE] .
4086
4085
*/
4087
- bool _checkForMapTypeNotAssignable (
4088
- MapLiteral literal, TypeArgumentList typeArguments) {
4089
- // Prepare maps key/value types.
4090
- NodeList <TypeName > typeNames = typeArguments.arguments;
4091
- if (typeNames.length < 2 ) {
4092
- return false ;
4093
- }
4094
- DartType keyType = typeNames[0 ].type;
4095
- DartType valueType = typeNames[1 ].type;
4096
- // Check every map entry.
4097
- bool hasProblems = false ;
4086
+ void _checkForMapTypeNotAssignable (MapLiteral literal) {
4087
+ // Determine the map's key and value types. We base this on the static type
4088
+ // and not the literal's type arguments because in strong mode, the type
4089
+ // arguments may be inferred.
4090
+ DartType mapType = literal.staticType;
4091
+ assert (mapType is InterfaceTypeImpl );
4092
+
4093
+ List <DartType > typeArguments =
4094
+ (mapType as InterfaceTypeImpl ).typeArguments;
4095
+ assert (typeArguments.length == 2 );
4096
+ DartType keyType = typeArguments[0 ];
4097
+ DartType valueType = typeArguments[1 ];
4098
+
4098
4099
NodeList <MapLiteralEntry > entries = literal.entries;
4099
4100
for (MapLiteralEntry entry in entries) {
4100
4101
Expression key = entry.key;
4101
4102
Expression value = entry.value;
4102
4103
if (literal.constKeyword != null ) {
4103
4104
// TODO(paulberry): this error should be based on the actual type of the
4104
4105
// list element, not the static type. See dartbug.com/21119.
4105
- if (_checkForArgumentTypeNotAssignableWithExpectedTypes (key, keyType,
4106
- CheckedModeCompileTimeErrorCode .MAP_KEY_TYPE_NOT_ASSIGNABLE )) {
4107
- hasProblems = true ;
4108
- }
4109
- if (_checkForArgumentTypeNotAssignableWithExpectedTypes (
4106
+ _checkForArgumentTypeNotAssignableWithExpectedTypes (key, keyType,
4107
+ CheckedModeCompileTimeErrorCode .MAP_KEY_TYPE_NOT_ASSIGNABLE );
4108
+ _checkForArgumentTypeNotAssignableWithExpectedTypes (
4110
4109
value,
4111
4110
valueType,
4112
- CheckedModeCompileTimeErrorCode .MAP_VALUE_TYPE_NOT_ASSIGNABLE )) {
4113
- hasProblems = true ;
4114
- }
4115
- }
4116
- if (_checkForArgumentTypeNotAssignableWithExpectedTypes (
4117
- key, keyType, StaticWarningCode .MAP_KEY_TYPE_NOT_ASSIGNABLE )) {
4118
- hasProblems = true ;
4119
- }
4120
- if (_checkForArgumentTypeNotAssignableWithExpectedTypes (
4121
- value, valueType, StaticWarningCode .MAP_VALUE_TYPE_NOT_ASSIGNABLE )) {
4122
- hasProblems = true ;
4111
+ CheckedModeCompileTimeErrorCode .MAP_VALUE_TYPE_NOT_ASSIGNABLE );
4123
4112
}
4113
+ _checkForArgumentTypeNotAssignableWithExpectedTypes (
4114
+ key, keyType, StaticWarningCode .MAP_KEY_TYPE_NOT_ASSIGNABLE );
4115
+ _checkForArgumentTypeNotAssignableWithExpectedTypes (
4116
+ value, valueType, StaticWarningCode .MAP_VALUE_TYPE_NOT_ASSIGNABLE );
4124
4117
}
4125
- return hasProblems;
4126
4118
}
4127
4119
4128
4120
/**
@@ -5694,25 +5686,23 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
5694
5686
: _typeProvider.iterableType;
5695
5687
5696
5688
// Use an explicit string instead of [loopType] to remove the "<E>".
5697
- String loopTypeName = node.awaitKeyword != null
5698
- ? "Stream"
5699
- : "Iterable" ;
5689
+ String loopTypeName = node.awaitKeyword != null ? "Stream" : "Iterable" ;
5700
5690
5701
5691
// The object being iterated has to implement Iterable<T> for some T that
5702
5692
// is assignable to the variable's type.
5703
5693
// TODO(rnystrom): Move this into mostSpecificTypeArgument()?
5704
5694
iterableType = iterableType.resolveToBound (_typeProvider.objectType);
5705
- DartType bestIterableType = _typeSystem. mostSpecificTypeArgument (
5706
- iterableType, loopType);
5695
+ DartType bestIterableType =
5696
+ _typeSystem. mostSpecificTypeArgument ( iterableType, loopType);
5707
5697
if (bestIterableType == null ) {
5708
5698
_errorReporter.reportTypeErrorForNode (
5709
5699
StaticTypeWarningCode .FOR_IN_OF_INVALID_TYPE ,
5710
- node,
5700
+ node.iterable ,
5711
5701
[iterableType, loopTypeName]);
5712
5702
} else if (! _typeSystem.isAssignableTo (bestIterableType, variableType)) {
5713
5703
_errorReporter.reportTypeErrorForNode (
5714
5704
StaticTypeWarningCode .FOR_IN_OF_INVALID_ELEMENT_TYPE ,
5715
- node,
5705
+ node.iterable ,
5716
5706
[iterableType, loopTypeName, variableType]);
5717
5707
}
5718
5708
}
0 commit comments