Eliminate uses of old AST node types from pkg/analyzer/lib/src/generated
Change-Id: Icba5f914248124909e38091f846054de8924adc8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/94993
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index 1b7bcd0..5645b59 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -741,13 +741,6 @@
}
@override
- @deprecated
- void visitForEachStatement(ForEachStatement node) {
- _checkForInIterable(node);
- super.visitForEachStatement(node);
- }
-
- @override
void visitFormalParameterList(FormalParameterList node) {
_checkDuplicateDefinitionInParameterList(node);
_checkUseOfCovariantInParameters(node);
@@ -774,18 +767,6 @@
}
@override
- @deprecated
- void visitForStatement(ForStatement node) {
- if (node.condition != null) {
- _checkForNonBoolCondition(node.condition);
- }
- if (node.variables != null) {
- _checkDuplicateVariables(node.variables);
- }
- super.visitForStatement(node);
- }
-
- @override
void visitFunctionDeclaration(FunctionDeclaration node) {
ExecutableElement functionElement = node.declaredElement;
if (functionElement != null &&
@@ -1015,28 +996,6 @@
}
@override
- @deprecated
- void visitMapLiteral(MapLiteral node) {
- TypeArgumentList typeArguments = node.typeArguments;
- if (typeArguments != null) {
- NodeList<TypeAnnotation> arguments = typeArguments.arguments;
- if (arguments.isNotEmpty) {
- if (node.isConst) {
- _checkForInvalidTypeArgumentInConstTypedLiteral(arguments,
- CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP);
- }
- }
- _checkTypeArgumentCount(typeArguments, 2,
- StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS);
- }
- _checkForRawTypedLiteral(node);
- _checkForImplicitDynamicTypedLiteral(node);
- _checkForMapTypeNotAssignable(node);
- _checkForNonConstMapAsExpressionStatement(node);
- super.visitMapLiteral(node);
- }
-
- @override
void visitMethodDeclaration(MethodDeclaration node) {
ExecutableElement previousFunction = _enclosingFunction;
try {
@@ -1222,28 +1181,6 @@
}
@override
- @deprecated
- void visitSetLiteral(SetLiteral node) {
- TypeArgumentList typeArguments = node.typeArguments;
- if (typeArguments != null) {
- if (node.isConst) {
- NodeList<TypeAnnotation> arguments = typeArguments.arguments;
- if (arguments.isNotEmpty) {
- _checkForInvalidTypeArgumentInConstTypedLiteral(arguments,
- CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_SET);
- }
- }
- _checkTypeArgumentCount(typeArguments, 1,
- StaticTypeWarningCode.EXPECTED_ONE_SET_TYPE_ARGUMENTS);
- }
- _checkForRawTypedLiteral(node);
- _checkForImplicitDynamicTypedLiteral(node);
- _checkForSetElementTypeNotAssignable(node);
-
- super.visitSetLiteral(node);
- }
-
- @override
void visitSetOrMapLiteral(SetOrMapLiteral node) {
TypeArgumentList typeArguments = node.typeArguments;
if (node.isMap) {
@@ -3809,84 +3746,6 @@
}
/**
- * Check for a type mis-match between the iterable expression and the
- * assigned variable in a for-in statement.
- */
- @deprecated
- void _checkForInIterable(ForEachStatement node) {
- DeclaredIdentifier loopVariable = node.loopVariable;
-
- // Ignore malformed for statements.
- if (node.identifier == null && loopVariable == null) {
- return;
- }
-
- if (_checkForNullableDereference(node.iterable)) {
- return;
- }
-
- if (_checkForUseOfVoidResult(node.iterable)) {
- return;
- }
-
- DartType iterableType = getStaticType(node.iterable);
- if (iterableType.isDynamic) {
- return;
- }
-
- // The type of the loop variable.
- SimpleIdentifier variable = node.identifier ?? loopVariable.identifier;
- DartType variableType = getStaticType(variable);
-
- DartType loopType = node.awaitKeyword != null
- ? _typeProvider.streamType
- : _typeProvider.iterableType;
-
- // Use an explicit string instead of [loopType] to remove the "<E>".
- String loopTypeName = node.awaitKeyword != null ? "Stream" : "Iterable";
-
- // The object being iterated has to implement Iterable<T> for some T that
- // is assignable to the variable's type.
- // TODO(rnystrom): Move this into mostSpecificTypeArgument()?
- iterableType = iterableType.resolveToBound(_typeProvider.objectType);
- DartType bestIterableType =
- _typeSystem.mostSpecificTypeArgument(iterableType, loopType);
-
- // Allow it to be a supertype of Iterable<T> (basically just Object) and do
- // an implicit downcast to Iterable<dynamic>.
- if (bestIterableType == null) {
- if (_typeSystem.isSubtypeOf(loopType, iterableType)) {
- bestIterableType = DynamicTypeImpl.instance;
- }
- }
-
- if (loopVariable != null) {
- if (loopVariable.isConst) {
- _errorReporter.reportErrorForNode(
- CompileTimeErrorCode.FOR_IN_WITH_CONST_VARIABLE, loopVariable);
- }
- } else if (node.identifier != null) {
- Element variableElement = node.identifier.staticElement;
- if (variableElement is VariableElement && variableElement.isConst) {
- _errorReporter.reportErrorForNode(
- CompileTimeErrorCode.FOR_IN_WITH_CONST_VARIABLE, node.identifier);
- }
- }
-
- if (bestIterableType == null) {
- _errorReporter.reportTypeErrorForNode(
- StaticTypeWarningCode.FOR_IN_OF_INVALID_TYPE,
- node.iterable,
- [iterableType, loopTypeName]);
- } else if (!_typeSystem.isAssignableTo(bestIterableType, variableType)) {
- _errorReporter.reportTypeErrorForNode(
- StaticTypeWarningCode.FOR_IN_OF_INVALID_ELEMENT_TYPE,
- node.iterable,
- [iterableType, loopTypeName, variableType]);
- }
- }
-
- /**
* Check that the given [typeReference] is not a type reference and that then
* the [name] is reference to an instance member.
*
@@ -4151,62 +4010,6 @@
}
}
- /**
- * Verify that the key/value of entries of the given map [literal] are
- * subtypes of the map's static type.
- *
- * See [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE],
- * [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE],
- * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and
- * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE].
- */
- @deprecated
- void _checkForMapTypeNotAssignable(MapLiteral literal) {
- // Determine the map's key and value types. We base this on the static type
- // and not the literal's type arguments because in strong mode, the type
- // arguments may be inferred.
- DartType mapType = literal.staticType;
- if (mapType == null) {
- // This is known to happen when the literal is the default value in an
- // optional parameter in a generic function type alias.
- return;
- }
- assert(mapType is InterfaceTypeImpl);
-
- List<DartType> typeArguments = (mapType as InterfaceTypeImpl).typeArguments;
- assert(typeArguments.length == 2);
- DartType keyType = typeArguments[0];
- DartType valueType = typeArguments[1];
-
- bool isConst = literal.isConst;
- NodeList<MapLiteralEntry> entries = literal.entries;
- for (MapLiteralEntry entry in entries) {
- Expression key = entry.key;
- Expression value = entry.value;
- if (isConst) {
- // TODO(paulberry): this error should be based on the actual type of the
- // list element, not the static type. See dartbug.com/21119.
- _checkForArgumentTypeNotAssignableWithExpectedTypes(key, keyType,
- CheckedModeCompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE);
- _checkForArgumentTypeNotAssignableWithExpectedTypes(value, valueType,
- CheckedModeCompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE);
- }
- _checkForArgumentTypeNotAssignableWithExpectedTypes(
- key, keyType, StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE);
- _checkForArgumentTypeNotAssignableWithExpectedTypes(
- value, valueType, StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE);
- }
- }
-
- /**
- * Verify that the key/value of entries of the given map [literal] are
- * subtypes of the map's static type.
- *
- * See [CompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE],
- * [CompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE],
- * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and
- * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE].
- */
void _checkForMapTypeNotAssignable3(SetOrMapLiteral literal) {
// Determine the map's key and value types. We base this on the static type
// and not the literal's type arguments because in strong mode, the type
@@ -4816,38 +4619,6 @@
*
* See [CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATEMENT].
*/
- @deprecated
- void _checkForNonConstMapAsExpressionStatement(MapLiteral literal) {
- // "const"
- if (literal.constKeyword != null) {
- return;
- }
- // has type arguments
- if (literal.typeArguments != null) {
- return;
- }
- // prepare statement
- Statement statement = literal.thisOrAncestorOfType<ExpressionStatement>();
- if (statement == null) {
- return;
- }
- // OK, statement does not start with map
- if (!identical(statement.beginToken, literal.beginToken)) {
- return;
- }
-
- _errorReporter.reportErrorForNode(
- CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATEMENT, literal);
- }
-
- /**
- * Verify the given map [literal] either:
- * * has `const modifier`
- * * has explicit type arguments
- * * is not start of the statement
- *
- * See [CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATEMENT].
- */
void _checkForNonConstMapAsExpressionStatement3(SetOrMapLiteral literal) {
// "const"
if (literal.constKeyword != null) {
@@ -5476,42 +5247,6 @@
* See [CompileTimeErrorCode.SET_ELEMENT_TYPE_NOT_ASSIGNABLE], and
* [StaticWarningCode.SET_ELEMENT_TYPE_NOT_ASSIGNABLE].
*/
- @deprecated
- void _checkForSetElementTypeNotAssignable(SetLiteral literal) {
- // 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.
- DartType setType = literal.staticType;
- assert(setType is InterfaceTypeImpl);
-
- List<DartType> typeArguments = (setType as InterfaceTypeImpl).typeArguments;
- assert(typeArguments.length == 1);
-
- DartType setElementType = typeArguments[0];
-
- // Check every set element.
- bool isConst = literal.isConst;
- for (Expression element in literal.elements) {
- if (isConst) {
- // TODO(paulberry): this error should be based on the actual type of the
- // element, not the static type. See dartbug.com/21119.
- _checkForArgumentTypeNotAssignableWithExpectedTypes(
- element,
- setElementType,
- CheckedModeCompileTimeErrorCode.SET_ELEMENT_TYPE_NOT_ASSIGNABLE);
- }
- _checkForArgumentTypeNotAssignableWithExpectedTypes(element,
- setElementType, StaticWarningCode.SET_ELEMENT_TYPE_NOT_ASSIGNABLE);
- }
- }
-
- /**
- * Verify that the elements in the given set [literal] are subtypes of the
- * set's static type.
- *
- * See [CompileTimeErrorCode.SET_ELEMENT_TYPE_NOT_ASSIGNABLE], and
- * [StaticWarningCode.SET_ELEMENT_TYPE_NOT_ASSIGNABLE].
- */
void _checkForSetElementTypeNotAssignable3(SetOrMapLiteral literal) {
// 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
@@ -6919,6 +6654,7 @@
*/
class _UninstantiatedBoundChecker extends RecursiveAstVisitor {
final ErrorReporter _errorReporter;
+
_UninstantiatedBoundChecker(this._errorReporter);
@override
diff --git a/pkg/analyzer/lib/src/generated/parser.dart b/pkg/analyzer/lib/src/generated/parser.dart
index 5ecd8d4..cd39326 100644
--- a/pkg/analyzer/lib/src/generated/parser.dart
+++ b/pkg/analyzer/lib/src/generated/parser.dart
@@ -3675,8 +3675,8 @@
///
/// mapLiteral ::=
/// 'const'? typeArguments? '{' (mapLiteralEntry (',' mapLiteralEntry)* ','?)? '}'
- MapLiteral // ignore: deprecated_member_use_from_same_package
- parseMapLiteral(Token modifier, TypeArgumentList typeArguments) {
+ SetOrMapLiteral parseMapLiteral(
+ Token modifier, TypeArgumentList typeArguments) {
Token leftBracket = getAndAdvance();
if (_matches(TokenType.CLOSE_CURLY_BRACKET)) {
// ignore: deprecated_member_use_from_same_package
@@ -4032,8 +4032,7 @@
_tokenMatchesKeyword(_peek(), Keyword.FOR)) {
Token awaitToken = _currentToken;
Statement statement = parseForStatement();
- // ignore: deprecated_member_use_from_same_package
- if (statement is! ForStatement) {
+ if (!(statement is ForStatement2 && statement.forLoopParts is ForParts)) {
_reportErrorForToken(
CompileTimeErrorCode.ASYNC_FOR_IN_WRONG_CONTEXT, awaitToken);
}
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index e162822..a22da7a 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -1135,8 +1135,6 @@
if (parent is IfStatement && parent.condition == childOfParent ||
parent is ForPartsWithDeclarations &&
parent.condition == childOfParent ||
- // ignore: deprecated_member_use_from_same_package
- parent is ForStatement && parent.condition == childOfParent ||
parent is DoStatement && parent.condition == childOfParent ||
parent is WhileStatement && parent.condition == childOfParent ||
parent is ConditionalExpression && parent.condition == childOfParent ||
@@ -4331,51 +4329,6 @@
}
@override
- @deprecated
- void visitForEachStatementInScope(ForEachStatement node) {
- Expression iterable = node.iterable;
- DeclaredIdentifier loopVariable = node.loopVariable;
- SimpleIdentifier identifier = node.identifier;
-
- identifier?.accept(this);
-
- DartType valueType;
- if (loopVariable != null) {
- TypeAnnotation typeAnnotation = loopVariable.type;
- valueType = typeAnnotation?.type ?? UnknownInferredType.instance;
- }
- if (identifier != null) {
- Element element = identifier.staticElement;
- if (element is VariableElement) {
- valueType = element.type;
- } else if (element is PropertyAccessorElement) {
- if (element.parameters.isNotEmpty) {
- valueType = element.parameters[0].type;
- }
- }
- }
- if (valueType != null) {
- InterfaceType targetType = (node.awaitKeyword == null)
- ? typeProvider.iterableType
- : typeProvider.streamType;
- InferenceContext.setType(iterable, targetType.instantiate([valueType]));
- }
-
- //
- // We visit the iterator before the loop variable because the loop variable
- // cannot be in scope while visiting the iterator.
- //
- iterable?.accept(this);
- loopVariable?.accept(this);
- Statement body = node.body;
- if (body != null) {
- visitStatementInScope(body);
- }
- node.accept(elementResolver);
- node.accept(typeAnalyzer);
- }
-
- @override
void visitForElement(ForElement node) {
ForLoopParts forLoopParts = node.forLoopParts;
if (forLoopParts is ForParts) {
@@ -4488,17 +4441,6 @@
}
@override
- @deprecated
- void visitForStatementInScope(ForStatement node) {
- node.variables?.accept(this);
- node.initialization?.accept(this);
- InferenceContext.setType(node.condition, typeProvider.boolType);
- node.condition?.accept(this);
- visitStatementInScope(node.body);
- node.updaters.accept(this);
- }
-
- @override
void visitFunctionDeclaration(FunctionDeclaration node) {
ExecutableElement outerFunction = _enclosingFunction;
FunctionBody outerFunctionBody = _currentFunctionBody;
@@ -4698,40 +4640,6 @@
}
@override
- @deprecated
- void visitMapLiteral(MapLiteral node) {
- InterfaceType mapT;
- if (node.typeArguments != null) {
- var targs = node.typeArguments.arguments.map((t) => t.type).toList();
- if (targs.length == 2 && targs.any((t) => !t.isDynamic)) {
- mapT = typeProvider.mapType.instantiate([targs[0], targs[1]]);
- }
- } else {
- mapT = typeAnalyzer.inferMapType(node, downwards: true);
- if (mapT != null &&
- node.typeArguments == null &&
- node.entries.isEmpty &&
- typeSystem.isAssignableTo(typeProvider.iterableObjectType, mapT) &&
- !typeSystem.isAssignableTo(typeProvider.mapObjectObjectType, mapT)) {
- // The node is really an empty set literal with no type arguments, so
- // don't try to visit the replaced map literal.
- return;
- }
- }
- if (mapT != null) {
- DartType kType = mapT.typeArguments[0];
- DartType vType = mapT.typeArguments[1];
- for (MapLiteralEntry entry in node.entries) {
- InferenceContext.setType(entry.key, kType);
- InferenceContext.setType(entry.value, vType);
- }
- InferenceContext.setType(node, mapT);
- } else {
- InferenceContext.clearType(node);
- }
- visitNode(node);
- }
-
@override
void visitMethodDeclaration(MethodDeclaration node) {
ExecutableElement outerFunction = _enclosingFunction;
@@ -4866,34 +4774,6 @@
}
@override
- @deprecated
- void visitSetLiteral(SetLiteral node) {
- InterfaceType setT;
-
- TypeArgumentList typeArguments = node.typeArguments;
- if (typeArguments != null) {
- if (typeArguments.length == 1) {
- DartType elementType = typeArguments.arguments[0].type;
- if (!elementType.isDynamic) {
- setT = typeProvider.setType.instantiate([elementType]);
- }
- }
- } else {
- setT = typeAnalyzer.inferSetType(node, downwards: true);
- }
- if (setT != null) {
- DartType eType = setT.typeArguments[0];
- for (Expression child in node.elements) {
- InferenceContext.setType(child, eType);
- }
- InferenceContext.setType(node, setT);
- } else {
- InferenceContext.clearType(node);
- }
- visitNode(node);
- }
-
- @override
void visitSetOrMapLiteral(SetOrMapLiteral node) {
DartType literalType = _computeContextType(node);
// TODO(brianwilkerson) Determine whether we need special handling for type
@@ -5899,38 +5779,6 @@
}
@override
- @deprecated
- void visitForEachStatement(ForEachStatement node) {
- Scope outerNameScope = nameScope;
- ImplicitLabelScope outerImplicitScope = _implicitLabelScope;
- try {
- nameScope = new EnclosedScope(nameScope);
- _implicitLabelScope = _implicitLabelScope.nest(node);
- visitForEachStatementInScope(node);
- } finally {
- nameScope = outerNameScope;
- _implicitLabelScope = outerImplicitScope;
- }
- }
-
- /// Visit the given statement after it's scope has been created. This replaces
- /// the normal call to the inherited visit method so that ResolverVisitor can
- /// intervene when type propagation is enabled.
- ///
- /// @param node the statement to be visited
- @deprecated
- void visitForEachStatementInScope(ForEachStatement node) {
- //
- // We visit the iterator before the loop variable because the loop variable
- // cannot be in scope while visiting the iterator.
- //
- node.identifier?.accept(this);
- node.iterable?.accept(this);
- node.loopVariable?.accept(this);
- visitStatementInScope(node.body);
- }
-
- @override
void visitFormalParameterList(FormalParameterList node) {
super.visitFormalParameterList(node);
// We finished resolving function signature, now include formal parameters
@@ -5947,21 +5795,6 @@
}
@override
- @deprecated
- void visitForStatement(ForStatement node) {
- Scope outerNameScope = nameScope;
- ImplicitLabelScope outerImplicitScope = _implicitLabelScope;
- try {
- nameScope = new EnclosedScope(nameScope);
- _implicitLabelScope = _implicitLabelScope.nest(node);
- visitForStatementInScope(node);
- } finally {
- nameScope = outerNameScope;
- _implicitLabelScope = outerImplicitScope;
- }
- }
-
- @override
void visitForStatement2(ForStatement2 node) {
Scope outerNameScope = nameScope;
ImplicitLabelScope outerImplicitScope = _implicitLabelScope;
@@ -5985,20 +5818,6 @@
visitStatementInScope(node.body);
}
- /// Visit the given statement after it's scope has been created. This replaces
- /// the normal call to the inherited visit method so that ResolverVisitor can
- /// intervene when type propagation is enabled.
- ///
- /// @param node the statement to be visited
- @deprecated
- void visitForStatementInScope(ForStatement node) {
- node.variables?.accept(this);
- node.initialization?.accept(this);
- node.condition?.accept(this);
- node.updaters.accept(this);
- visitStatementInScope(node.body);
- }
-
@override
void visitFunctionDeclaration(FunctionDeclaration node) {
ExecutableElement functionElement = node.declaredElement;
diff --git a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
index e39ffad..da50a41 100644
--- a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
+++ b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
@@ -10,10 +10,7 @@
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
-import 'package:analyzer/src/dart/analysis/experiments.dart';
import 'package:analyzer/src/dart/ast/ast.dart';
-import 'package:analyzer/src/dart/ast/ast_factory.dart';
-import 'package:analyzer/src/dart/ast/utilities.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/dart/element/member.dart' show ConstructorMember;
import 'package:analyzer/src/dart/element/type.dart';
@@ -55,11 +52,6 @@
DartType _dynamicType;
/**
- * The status of the active experiments of the current context.
- */
- ExperimentStatus _experimentStatus;
-
- /**
* True if inference failures should be reported, otherwise false.
*/
bool _strictInference;
@@ -87,7 +79,6 @@
_promoteManager = _resolver.promoteManager;
AnalysisOptionsImpl analysisOptions =
_resolver.definingLibrary.context.analysisOptions;
- _experimentStatus = analysisOptions.experimentStatus;
_strictInference = analysisOptions.strictInference;
}
@@ -189,106 +180,6 @@
return inferred;
}
- @deprecated
- ParameterizedType inferMapType(MapLiteral node, {bool downwards: false}) {
- DartType contextType = InferenceContext.getContext(node);
- if (contextType != null && _experimentStatus.set_literals) {
- DartType unwrap(DartType type) {
- if (type is InterfaceType &&
- type.isDartAsyncFutureOr &&
- type.typeArguments.length == 1) {
- return unwrap(type.typeArguments[0]);
- }
- return type;
- }
-
- DartType unwrappedContextType = unwrap(contextType);
- if (node.typeArguments == null &&
- node.entries.isEmpty &&
- _typeSystem.isAssignableTo(
- _typeProvider.iterableObjectType, unwrappedContextType) &&
- !_typeSystem.isAssignableTo(
- _typeProvider.mapObjectObjectType, unwrappedContextType)) {
- // The node is really an empty set literal with no type arguments.
- // Rewrite the AST and infer the type of the set as appropriate.
- SetLiteral setLiteral = new AstFactoryImpl().setLiteral(
- node.constKeyword, null, node.leftBracket, null, node.rightBracket);
- InferenceContext.setType(setLiteral, contextType);
- NodeReplacer.replace(node, setLiteral);
- DartType type = inferSetType(setLiteral, downwards: downwards);
- setLiteral.staticType = type;
- return type;
- }
- }
- List<DartType> elementTypes;
- List<ParameterElement> parameters;
- if (downwards) {
- if (contextType == null) {
- return null;
- }
- elementTypes = [];
- parameters = [];
- } else {
- var keyTypes =
- node.entries.map((e) => e.key.staticType).where((t) => t != null);
- var valueTypes =
- node.entries.map((e) => e.value.staticType).where((t) => t != null);
- var keyTypeParam = _typeProvider.mapType.typeParameters[0].type;
- var valueTypeParam = _typeProvider.mapType.typeParameters[1].type;
- var syntheticKeyParameter = new ParameterElementImpl.synthetic(
- 'key', keyTypeParam, ParameterKind.POSITIONAL);
- var syntheticValueParameter = new ParameterElementImpl.synthetic(
- 'value', valueTypeParam, ParameterKind.POSITIONAL);
- parameters = new List.filled(keyTypes.length, syntheticKeyParameter,
- growable: true)
- ..addAll(new List.filled(valueTypes.length, syntheticValueParameter));
- elementTypes = new List<DartType>.from(keyTypes)..addAll(valueTypes);
- }
-
- // Use both downwards and upwards information to infer the type.
- var ts = _typeSystem as Dart2TypeSystem;
- ParameterizedType inferred = ts.inferGenericFunctionOrType(
- _typeProvider.mapType, parameters, elementTypes, contextType,
- downwards: downwards,
- errorReporter: _resolver.errorReporter,
- errorNode: node);
- return inferred;
- }
-
- @deprecated
- DartType inferSetType(SetLiteral node, {bool downwards: false}) {
- DartType contextType = InferenceContext.getContext(node);
-
- var ts = _typeSystem as Dart2TypeSystem;
- List<DartType> elementTypes;
- List<ParameterElement> parameters;
-
- if (downwards) {
- if (contextType == null) {
- return null;
- }
-
- elementTypes = [];
- parameters = [];
- } else {
- // Also use upwards information to infer the type.
- elementTypes = node.elements
- .map((e) => e.staticType)
- .where((t) => t != null)
- .toList();
- var setTypeParam = _typeProvider.setType.typeParameters[0].type;
- var syntheticParamElement = new ParameterElementImpl.synthetic(
- 'element', setTypeParam, ParameterKind.POSITIONAL);
- parameters = new List.filled(elementTypes.length, syntheticParamElement);
- }
- DartType inferred = ts.inferGenericFunctionOrType<InterfaceType>(
- _typeProvider.setType, parameters, elementTypes, contextType,
- downwards: downwards,
- errorReporter: _resolver.errorReporter,
- errorNode: node);
- return inferred;
- }
-
/**
* The Dart Language Specification, 12.5: <blockquote>The static type of a string literal is
* `String`.</blockquote>
@@ -704,65 +595,6 @@
}
/**
- * The Dart Language Specification, 12.7: <blockquote>The static type of a map literal of the form
- * <i><b>const</b> <K, V> {k<sub>1</sub>:e<sub>1</sub>, …,
- * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i><K, V> {k<sub>1</sub>:e<sub>1</sub>,
- * …, k<sub>n</sub>:e<sub>n</sub>}</i> is `Map<K, V>`. The static type a map
- * literal of the form <i><b>const</b> {k<sub>1</sub>:e<sub>1</sub>, …,
- * k<sub>n</sub>:e<sub>n</sub>}</i> or the form <i>{k<sub>1</sub>:e<sub>1</sub>, …,
- * k<sub>n</sub>:e<sub>n</sub>}</i> is `Map<dynamic, dynamic>`.
- *
- * It is a compile-time error if the first type argument to a map literal is not
- * <i>String</i>.</blockquote>
- */
- @override
- @deprecated
- void visitMapLiteral(MapLiteral node) {
- TypeArgumentList typeArguments = node.typeArguments;
-
- // If we have type arguments, use them
- if (typeArguments != null) {
- DartType staticKeyType = _dynamicType;
- DartType staticValueType = _dynamicType;
- NodeList<TypeAnnotation> arguments = typeArguments.arguments;
- if (arguments != null && arguments.length == 2) {
- DartType entryKeyType = _getType(arguments[0]);
- if (entryKeyType != null) {
- staticKeyType = entryKeyType;
- }
- DartType entryValueType = _getType(arguments[1]);
- if (entryValueType != null) {
- staticValueType = entryValueType;
- }
- }
- _recordStaticType(
- node,
- _typeProvider.mapType
- .instantiate(<DartType>[staticKeyType, staticValueType]));
- return;
- }
-
- DartType mapDynamicType = _typeProvider.mapType
- .instantiate(<DartType>[_dynamicType, _dynamicType]);
-
- // If we have no explicit type arguments, try to infer type arguments.
- ParameterizedType inferred = inferMapType(node);
-
- if (inferred != mapDynamicType) {
- // TODO(jmesserly): this results in an "inferred" message even when we
- // in fact had an error above, because it will still attempt to return
- // a type. Perhaps we should record inference from TypeSystem if
- // everything was successful?
- _resolver.inferenceContext.recordInference(node, inferred);
- _recordStaticType(node, inferred);
- return;
- }
-
- // If no type arguments and no inference, use dynamic
- _recordStaticType(node, mapDynamicType);
- }
-
- /**
* The Dart Language Specification, 12.15.1: <blockquote>An ordinary method invocation <i>i</i>
* has the form <i>o.m(a<sub>1</sub>, …, a<sub>n</sub>, x<sub>n+1</sub>: a<sub>n+1</sub>,
* …, x<sub>n+k</sub>: a<sub>n+k</sub>)</i>.
@@ -1010,46 +842,6 @@
}
@override
- @deprecated
- void visitSetLiteral(SetLiteral node) {
- TypeArgumentList typeArguments = node.typeArguments;
-
- // If we have type arguments, use them
- if (typeArguments != null) {
- DartType elementType = _dynamicType;
- NodeList<TypeAnnotation> arguments = typeArguments.arguments;
- if (arguments != null && arguments.length == 1) {
- DartType type = _getType(arguments[0]);
- if (type != null) {
- elementType = type;
- }
- }
- _recordStaticType(
- node, _typeProvider.setType.instantiate(<DartType>[elementType]));
- return;
- }
-
- DartType setDynamicType =
- _typeProvider.setType.instantiate(<DartType>[_dynamicType]);
-
- // If we have no explicit type arguments, try to infer type arguments.
- ParameterizedType inferred = inferSetType(node);
-
- if (inferred != setDynamicType) {
- // TODO(jmesserly): this results in an "inferred" message even when we
- // in fact had an error above, because it will still attempt to return
- // a type. Perhaps we should record inference from TypeSystem if
- // everything was successful?
- _resolver.inferenceContext.recordInference(node, inferred);
- _recordStaticType(node, inferred);
- return;
- }
-
- // If no type arguments and no inference, use dynamic
- _recordStaticType(node, setDynamicType);
- }
-
- @override
void visitSetOrMapLiteral(SetOrMapLiteral node) {
var typeArguments = node.typeArguments?.arguments;
@@ -1649,11 +1441,7 @@
AstNode parent = loopVariable.parent;
Token awaitKeyword;
Expression iterable;
- // ignore: deprecated_member_use_from_same_package
- if (parent is ForEachStatement) {
- awaitKeyword = parent.awaitKeyword;
- iterable = parent.iterable;
- } else if (parent is ForEachPartsWithDeclaration) {
+ if (parent is ForEachPartsWithDeclaration) {
AstNode parentParent = parent.parent;
if (parentParent is ForStatement2Impl) {
awaitKeyword = parentParent.awaitKeyword;
diff --git a/pkg/analyzer/lib/src/generated/testing/ast_test_factory.dart b/pkg/analyzer/lib/src/generated/testing/ast_test_factory.dart
index 296457a..5d1c4d6 100644
--- a/pkg/analyzer/lib/src/generated/testing/ast_test_factory.dart
+++ b/pkg/analyzer/lib/src/generated/testing/ast_test_factory.dart
@@ -495,7 +495,7 @@
fieldFormalParameter(null, null, identifier);
@Deprecated('Use forStatement2')
- static ForEachStatement forEachStatement(DeclaredIdentifier loopVariable,
+ static ForStatement2 forEachStatement(DeclaredIdentifier loopVariable,
Expression iterator, Statement body) =>
astFactory.forStatement2(
forKeyword: TokenFactory.tokenFromKeyword(Keyword.FOR),
@@ -508,7 +508,7 @@
body: body);
@Deprecated('Use forStatement2')
- static ForEachStatement forEachStatement2(
+ static ForStatement2 forEachStatement2(
SimpleIdentifier identifier, Expression iterator, Statement body) =>
astFactory.forStatement2(
forKeyword: TokenFactory.tokenFromKeyword(Keyword.FOR),
@@ -530,7 +530,7 @@
TokenFactory.tokenFromType(TokenType.CLOSE_PAREN));
@Deprecated('Use forStatement2')
- static ForStatement forStatement(Expression initialization,
+ static ForStatement2 forStatement(Expression initialization,
Expression condition, List<Expression> updaters, Statement body) =>
astFactory.forStatement2(
forKeyword: TokenFactory.tokenFromKeyword(Keyword.FOR),
@@ -544,27 +544,19 @@
rightParenthesis: TokenFactory.tokenFromType(TokenType.CLOSE_PAREN),
body: body);
- static
- // ignore: deprecated_member_use_from_same_package
- ForStatement forStatement2(
- VariableDeclarationList variableList,
- Expression condition,
- List<Expression> updaters,
- Statement body) =>
- astFactory.forStatement2(
- forKeyword: TokenFactory.tokenFromKeyword(Keyword.FOR),
- leftParenthesis: TokenFactory.tokenFromType(TokenType.OPEN_PAREN),
- forLoopParts: astFactory.forPartsWithDeclarations(
- variables: variableList,
- leftSeparator:
- TokenFactory.tokenFromType(TokenType.SEMICOLON),
- condition: condition,
- rightSeparator:
- TokenFactory.tokenFromType(TokenType.SEMICOLON),
- updaters: updaters),
- rightParenthesis:
- TokenFactory.tokenFromType(TokenType.CLOSE_PAREN),
- body: body);
+ static ForStatement2 forStatement2(VariableDeclarationList variableList,
+ Expression condition, List<Expression> updaters, Statement body) =>
+ astFactory.forStatement2(
+ forKeyword: TokenFactory.tokenFromKeyword(Keyword.FOR),
+ leftParenthesis: TokenFactory.tokenFromType(TokenType.OPEN_PAREN),
+ forLoopParts: astFactory.forPartsWithDeclarations(
+ variables: variableList,
+ leftSeparator: TokenFactory.tokenFromType(TokenType.SEMICOLON),
+ condition: condition,
+ rightSeparator: TokenFactory.tokenFromType(TokenType.SEMICOLON),
+ updaters: updaters),
+ rightParenthesis: TokenFactory.tokenFromType(TokenType.CLOSE_PAREN),
+ body: body);
static FunctionDeclaration functionDeclaration(
TypeAnnotation type,
@@ -834,7 +826,8 @@
TokenFactory.tokenFromType(TokenType.CLOSE_SQUARE_BRACKET));
@Deprecated('Use setOrMapLiteral')
- static MapLiteral mapLiteral(Keyword keyword, TypeArgumentList typeArguments,
+ static SetOrMapLiteral mapLiteral(
+ Keyword keyword, TypeArgumentList typeArguments,
[List<MapLiteralEntry> entries]) =>
astFactory.mapLiteral(
keyword == null ? null : TokenFactory.tokenFromKeyword(keyword),
@@ -844,7 +837,7 @@
TokenFactory.tokenFromType(TokenType.CLOSE_CURLY_BRACKET));
@Deprecated('Use setOrMapLiteral')
- static MapLiteral mapLiteral2([List<MapLiteralEntry> entries]) =>
+ static SetOrMapLiteral mapLiteral2([List<MapLiteralEntry> entries]) =>
mapLiteral(null, null, entries);
static MapLiteralEntry mapLiteralEntry(String key, Expression value) =>
@@ -1087,8 +1080,8 @@
astFactory.scriptTag(TokenFactory.tokenFromString(scriptTag));
@Deprecated('Use setOrMapLiteral')
- static SetLiteral setLiteral(Keyword keyword, TypeArgumentList typeArguments,
- List<Expression> elements) =>
+ static SetOrMapLiteral setLiteral(Keyword keyword,
+ TypeArgumentList typeArguments, List<Expression> elements) =>
astFactory.setLiteral(
keyword == null ? null : TokenFactory.tokenFromKeyword(keyword),
typeArguments,
diff --git a/pkg/analyzer/test/generated/static_type_analyzer_test.dart b/pkg/analyzer/test/generated/static_type_analyzer_test.dart
index 020414b..4ea099f 100644
--- a/pkg/analyzer/test/generated/static_type_analyzer_test.dart
+++ b/pkg/analyzer/test/generated/static_type_analyzer_test.dart
@@ -1671,7 +1671,7 @@
LinkedHashSet<int> test4() => {};
''';
await resolveTestUnit(code, noErrors: false);
- expectExpressionType('{}', 'Set<?>');
+ expectExpressionType('{}', 'Set<dynamic>');
await assertErrorsInCode(code, [StrongModeCode.INVALID_CAST_LITERAL_SET]);
}
diff --git a/pkg/analyzer/test/src/dart/resolution/type_inference/set_literal_test.dart b/pkg/analyzer/test/src/dart/resolution/type_inference/set_literal_test.dart
index b4bd6a9..be7fecb 100644
--- a/pkg/analyzer/test/src/dart/resolution/type_inference/set_literal_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/type_inference/set_literal_test.dart
@@ -44,6 +44,9 @@
assertType(setLiteral('{'), 'Set<String>');
}
+ @FailingTest(
+ issue: 'https://github.com/dart-lang/sdk/issues/35569',
+ reason: 'Failing because Map<dynamic, dynamic> is being inferred.')
test_context_noTypeArgs_noElements_typeParameter() async {
addTestFile('''
class A<E extends Set<int>> {
@@ -139,13 +142,6 @@
@override
AstNode setLiteral(String search) => findNode.setOrMapLiteral(search);
- @failingTest
- @override
- test_context_noTypeArgs_noElements_typeParameter() async {
- // Failing because Map<dynamic, dynamic> is being inferred.
- await super.test_context_noTypeArgs_noElements_typeParameter();
- }
-
test_noContext_noTypeArgs_forEachWithDeclaration() async {
addTestFile('''
var c = [1, 2, 3];
diff --git a/pkg/analyzer/test/src/diagnostics/map_key_type_not_assignable_test.dart b/pkg/analyzer/test/src/diagnostics/map_key_type_not_assignable_test.dart
index 7ca4508..5584706 100644
--- a/pkg/analyzer/test/src/diagnostics/map_key_type_not_assignable_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/map_key_type_not_assignable_test.dart
@@ -17,6 +17,7 @@
@reflectiveTest
class MapKeyTypeNotAssignableTest extends DriverResolutionTest {
+ @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/35569')
test_explicitTypeArgs_const() async {
// TODO(brianwilkerson) Fix this so that only one error is produced.
await assertErrorsInCode('''
diff --git a/pkg/analyzer/test/src/diagnostics/map_value_type_not_assignable_test.dart b/pkg/analyzer/test/src/diagnostics/map_value_type_not_assignable_test.dart
index 9e37ff1..60b18a8 100644
--- a/pkg/analyzer/test/src/diagnostics/map_value_type_not_assignable_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/map_value_type_not_assignable_test.dart
@@ -17,6 +17,7 @@
@reflectiveTest
class MapValueTypeNotAssignableTest extends DriverResolutionTest {
+ @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/35569')
test_explicitTypeArgs_const() async {
// TODO(brianwilkerson) Fix this so that only one error is produced.
await assertErrorsInCode('''
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 85f9a81..16f26ad 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
@@ -17,6 +17,7 @@
@reflectiveTest
class SetElementTypeNotAssignableTest extends DriverResolutionTest {
+ @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/35569')
test_explicitTypeArgs_const() async {
// TODO(brianwilkerson) Fix this so that only one error is produced.
await assertErrorsInCode('''
diff --git a/pkg/analyzer/test/src/task/strong/checker_test.dart b/pkg/analyzer/test/src/task/strong/checker_test.dart
index 0d931a6..408b75a 100644
--- a/pkg/analyzer/test/src/task/strong/checker_test.dart
+++ b/pkg/analyzer/test/src/task/strong/checker_test.dart
@@ -2305,11 +2305,11 @@
test_implicitDynamic_mapLiteral() async {
addFile(r'''
-var m0 = /*error:IMPLICIT_DYNAMIC_MAP_LITERAL*/{};
-Map m1 = /*error:IMPLICIT_DYNAMIC_MAP_LITERAL*/{};
-Map<dynamic, dynamic> m2 = /*error:IMPLICIT_DYNAMIC_MAP_LITERAL*/{};
+var m0 = /*info:INFERRED_TYPE_LITERAL,error:IMPLICIT_DYNAMIC_MAP_LITERAL*/{};
+Map m1 = /*info:INFERRED_TYPE_LITERAL,error:IMPLICIT_DYNAMIC_MAP_LITERAL*/{};
+Map<dynamic, dynamic> m2 = /*info:INFERRED_TYPE_LITERAL,error:IMPLICIT_DYNAMIC_MAP_LITERAL*/{};
dynamic d = 42;
-var m3 = /*error:IMPLICIT_DYNAMIC_MAP_LITERAL*/{d: d};
+var m3 = /*info:INFERRED_TYPE_LITERAL,error:IMPLICIT_DYNAMIC_MAP_LITERAL*/{d: d};
var m4 = /*info:INFERRED_TYPE_LITERAL,error:IMPLICIT_DYNAMIC_MAP_LITERAL*/{'x': d, 'y': d};
var m5 = /*info:INFERRED_TYPE_LITERAL,error:IMPLICIT_DYNAMIC_MAP_LITERAL*/{d: 'x'};
@@ -3647,6 +3647,16 @@
''');
}
+ @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/35569')
+ test_strictRawTypes_emptyMap() async {
+ addFile('''
+main() {
+ var rawMap = /*info:STRICT_RAW_TYPE*/{};
+}
+''');
+ await check(strictRawTypes: true);
+ }
+
test_strictRawTypes_classes() async {
addFile(r'''
class C<T> {
@@ -3744,7 +3754,6 @@
var upwardsInferNonDynamicIsOK = {4: 2};
var explicitDynamicIsOK = <dynamic, dynamic>{4: 2};
- var rawMap = /*info:STRICT_RAW_TYPE*/{};
var rawMapOfMaps = </*info:STRICT_RAW_TYPE*/Map>{};
/*info:STRICT_RAW_TYPE*/Map rawMapFromType = {};
@@ -4153,13 +4162,13 @@
// TODO(leafp): We can't currently test for key errors since the
// error marker binds to the entire entry.
{
- Map m = {s: i};
- m = {s: s};
- m = {s: n};
- m = {s: i,
+ Map m = /*info:INFERRED_TYPE_LITERAL*/{s: i};
+ m = /*info:INFERRED_TYPE_LITERAL*/{s: s};
+ m = /*info:INFERRED_TYPE_LITERAL*/{s: n};
+ m = /*info:INFERRED_TYPE_LITERAL*/{s: i,
s: n,
s: s};
- m = {i: s,
+ m = /*info:INFERRED_TYPE_LITERAL*/{i: s,
n: s,
s: s};
}
diff --git a/pkg/analyzer/test/src/task/strong/inferred_type_test.dart b/pkg/analyzer/test/src/task/strong/inferred_type_test.dart
index 777c51f..91f6c6f 100644
--- a/pkg/analyzer/test/src/task/strong/inferred_type_test.dart
+++ b/pkg/analyzer/test/src/task/strong/inferred_type_test.dart
@@ -1405,6 +1405,7 @@
''');
}
+ @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/35569')
test_downwardsInferenceOnMapLiterals() async {
await checkFileElement('''
void foo([Map<int, String> m1 = /*info:INFERRED_TYPE_LITERAL*/const {1: "hello"},
@@ -1486,6 +1487,7 @@
''');
}
+ @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/35569')
test_downwardsInferenceYieldYieldStar() async {
await checkFileElement('''
import 'dart:async';
@@ -2521,6 +2523,7 @@
expect(v.type.toString(), 'List<(int) → Object>');
}
+ @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/35569')
test_inferFromComplexExpressionsIfOuterMostValueIsPrecise() async {
await checkFileElement('''
class A { int x; B operator+(other) => null; }
@@ -4507,6 +4510,7 @@
}
@override
+ @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/35569')
test_downwardsInferenceYieldYieldStar() async {
// The fifth to last case is inferred differently with set_literals enabled,
// and no longer an error compared to the base implementation.