Remove UndefinedTypeImpl.
And corresponding DartType.isUndefined as well.
R=brianwilkerson@google.com, paulberry@google.com
Change-Id: I85debe627e989b5a5671becf5d9dd16413562236
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99729
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/utilities.dart b/pkg/analysis_server/lib/src/services/completion/dart/utilities.dart
index 409b979..a40613c 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/utilities.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/utilities.dart
@@ -213,7 +213,7 @@
}
// If the type is unresolved, use the declared type.
- if (type != null && type.isUndefined) {
+ if (type != null && type.isDynamic) {
if (declaredType is TypeName) {
Identifier id = declaredType.name;
if (id != null) {
diff --git a/pkg/analyzer/CHANGELOG.md b/pkg/analyzer/CHANGELOG.md
index e30b6cf..86763bf 100644
--- a/pkg/analyzer/CHANGELOG.md
+++ b/pkg/analyzer/CHANGELOG.md
@@ -1,3 +1,6 @@
+## 0.36.1
+* Deprecated `DartType.isUndefined`, and now it always returns `false`.
+
## 0.36.0
* Changed the return type of `Expression.precendence` to `Precedence`. Clients
that prepared for this change by switching to `Expression.precedence2` should
diff --git a/pkg/analyzer/lib/dart/element/type.dart b/pkg/analyzer/lib/dart/element/type.dart
index 7c752c2..ce67ab7 100644
--- a/pkg/analyzer/lib/dart/element/type.dart
+++ b/pkg/analyzer/lib/dart/element/type.dart
@@ -80,6 +80,7 @@
/// Return `true` if this type represents a typename that couldn't be
/// resolved.
+ @deprecated
bool get isUndefined;
/// Return `true` if this type represents the type 'void'.
diff --git a/pkg/analyzer/lib/src/dart/constant/evaluation.dart b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
index 112dce6..6633be9 100644
--- a/pkg/analyzer/lib/src/dart/constant/evaluation.dart
+++ b/pkg/analyzer/lib/src/dart/constant/evaluation.dart
@@ -902,9 +902,6 @@
if (obj.isNull) {
return true;
}
- if (type.isUndefined) {
- return false;
- }
var objType = obj.type;
if (objType.isDartCoreInt && type.isDartCoreDouble) {
// Work around dartbug.com/35993 by allowing `int` to be used in a place
diff --git a/pkg/analyzer/lib/src/dart/element/type.dart b/pkg/analyzer/lib/src/dart/element/type.dart
index 267f338..3f36fcf 100644
--- a/pkg/analyzer/lib/src/dart/element/type.dart
+++ b/pkg/analyzer/lib/src/dart/element/type.dart
@@ -3265,87 +3265,6 @@
}
/**
- * The unique instance of the class `UndefinedTypeImpl` implements the type of
- * type names that couldn't be resolved.
- *
- * This class behaves like DynamicTypeImpl in almost every respect, to reduce
- * cascading errors.
- */
-class UndefinedTypeImpl extends TypeImpl {
- /**
- * The unique instance of this class.
- */
- static final UndefinedTypeImpl instance = new UndefinedTypeImpl._();
-
- /**
- * Prevent the creation of instances of this class.
- */
- UndefinedTypeImpl._()
- : super(DynamicElementImpl.instance, Keyword.DYNAMIC.lexeme);
-
- @override
- int get hashCode => 1;
-
- @override
- bool get isDynamic => true;
-
- @override
- bool get isUndefined => true;
-
- @override
- NullabilitySuffix get nullabilitySuffix => NullabilitySuffix.star;
-
- @override
- bool operator ==(Object object) => identical(object, this);
-
- @override
- bool isMoreSpecificThan(DartType type,
- [bool withDynamic = false, Set<Element> visitedElements]) {
- // T is S
- if (identical(this, type)) {
- return true;
- }
- // else
- return withDynamic;
- }
-
- @override
- bool isSubtypeOf(DartType type) => true;
-
- @override
- bool isSupertypeOf(DartType type) => true;
-
- @override
- TypeImpl pruned(List<FunctionTypeAliasElement> prune) => this;
-
- @override
- DartType replaceTopAndBottom(TypeProvider typeProvider,
- {bool isCovariant = true}) {
- if (isCovariant) {
- return typeProvider.nullType;
- } else {
- return this;
- }
- }
-
- @override
- DartType substitute2(
- List<DartType> argumentTypes, List<DartType> parameterTypes,
- [List<FunctionTypeAliasElement> prune]) {
- int length = parameterTypes.length;
- for (int i = 0; i < length; i++) {
- if (parameterTypes[i] == this) {
- return argumentTypes[i];
- }
- }
- return this;
- }
-
- @override
- TypeImpl withNullability(NullabilitySuffix nullabilitySuffix) => this;
-}
-
-/**
* The type `void`.
*/
abstract class VoidType implements DartType {
diff --git a/pkg/analyzer/lib/src/generated/declaration_resolver.dart b/pkg/analyzer/lib/src/generated/declaration_resolver.dart
index b956a8a..582ab2d 100644
--- a/pkg/analyzer/lib/src/generated/declaration_resolver.dart
+++ b/pkg/analyzer/lib/src/generated/declaration_resolver.dart
@@ -735,7 +735,7 @@
/// corresponding type arguments of the [typeArguments].
static void _applyTypeArgumentsToList(LibraryElement enclosingLibraryElement,
DartType type, List<TypeAnnotation> typeArguments) {
- if (type != null && type.isUndefined) {
+ if (type != null && type.isDynamic) {
for (TypeAnnotation argument in typeArguments) {
applyToTypeAnnotation(enclosingLibraryElement, type, argument);
}
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index 49ba32d..1ff7522 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -6255,7 +6255,6 @@
class TypeNameResolver {
final TypeSystem typeSystem;
final DartType dynamicType;
- final DartType undefinedType;
final bool isNonNullableUnit;
final AnalysisOptionsImpl analysisOptions;
final LibraryElement definingLibrary;
@@ -6280,7 +6279,6 @@
this.errorListener,
{this.shouldUseWithClauseInferredTypes: true})
: dynamicType = typeProvider.dynamicType,
- undefinedType = typeProvider.undefinedType,
analysisOptions = definingLibrary.context.analysisOptions;
/// Report an error with the given error code and arguments.
@@ -6322,8 +6320,8 @@
return;
}
if (nameScope.shouldIgnoreUndefined(typeName)) {
- typeName.staticType = undefinedType;
- node.type = undefinedType;
+ typeName.staticType = dynamicType;
+ node.type = dynamicType;
return;
}
//
@@ -6343,8 +6341,8 @@
element = nameScope.lookup(prefix, definingLibrary);
if (element is PrefixElement) {
if (nameScope.shouldIgnoreUndefined(typeName)) {
- typeName.staticType = undefinedType;
- node.type = undefinedType;
+ typeName.staticType = dynamicType;
+ node.type = dynamicType;
return;
}
AstNode grandParent = parent.parent;
@@ -6382,8 +6380,8 @@
}
}
if (nameScope.shouldIgnoreUndefined(typeName)) {
- typeName.staticType = undefinedType;
- node.type = undefinedType;
+ typeName.staticType = dynamicType;
+ node.type = dynamicType;
return;
}
}
@@ -6500,8 +6498,8 @@
if (element is MultiplyDefinedElement) {
_setElement(typeName, element);
}
- typeName.staticType = undefinedType;
- node.type = undefinedType;
+ typeName.staticType = dynamicType;
+ node.type = dynamicType;
return;
}
@@ -6674,7 +6672,7 @@
DartType _getType(TypeAnnotation annotation) {
DartType type = annotation.type;
if (type == null) {
- return undefinedType;
+ return dynamicType;
}
return type;
}
@@ -7231,9 +7229,6 @@
/// Return the type representing the built-in type 'Type'.
InterfaceType get typeType;
- /// Return the type representing typenames that can't be resolved.
- DartType get undefinedType;
-
/// Return 'true' if [id] is the name of a getter on
/// the Object type.
bool isObjectGetter(String id);
@@ -7372,9 +7367,6 @@
/// The type representing the built-in type 'Type'.
InterfaceType _typeType;
- /// The type representing typenames that can't be resolved.
- DartType _undefinedType;
-
/// Initialize a newly created type provider to provide the types defined in
/// the given [coreLibrary] and [asyncLibrary].
TypeProviderImpl(LibraryElement coreLibrary, LibraryElement asyncLibrary) {
@@ -7476,9 +7468,6 @@
@override
InterfaceType get typeType => _typeType;
- @override
- DartType get undefinedType => _undefinedType;
-
InterfaceType _createNever(Namespace namespace) {
// TODO(brianwilkerson) Remove this method when the class is defined in the
// SDK.
@@ -7533,7 +7522,6 @@
_stringType = _getType(coreNamespace, 'String');
_symbolType = _getType(coreNamespace, 'Symbol');
_typeType = _getType(coreNamespace, 'Type');
- _undefinedType = UndefinedTypeImpl.instance;
_futureDynamicType = _futureType.instantiate(<DartType>[_dynamicType]);
_futureNullType = _futureType.instantiate(<DartType>[_nullType]);
_iterableDynamicType = _iterableType.instantiate(<DartType>[_dynamicType]);
@@ -7587,9 +7575,6 @@
/// The type representing the type 'dynamic'.
DartType _dynamicType;
- /// The type representing typenames that can't be resolved.
- DartType _undefinedType;
-
/// The flag specifying if currently visited class references 'super'
/// expression.
bool _hasReferenceToSuper = false;
@@ -7645,7 +7630,6 @@
: super(definingLibrary, source, typeProvider, errorListener,
nameScope: nameScope) {
_dynamicType = typeProvider.dynamicType;
- _undefinedType = typeProvider.undefinedType;
_typeSystem = TypeSystem.create(definingLibrary.context);
_typeNameResolver = new TypeNameResolver(_typeSystem, typeProvider,
isNonNullableUnit, definingLibrary, source, errorListener,
diff --git a/pkg/analyzer/lib/src/generated/testing/test_type_provider.dart b/pkg/analyzer/lib/src/generated/testing/test_type_provider.dart
index bb052ad..da58fd1 100644
--- a/pkg/analyzer/lib/src/generated/testing/test_type_provider.dart
+++ b/pkg/analyzer/lib/src/generated/testing/test_type_provider.dart
@@ -179,11 +179,6 @@
InterfaceType _typeType;
/**
- * The type representing type names that can't be resolved.
- */
- DartType _undefinedType;
-
- /**
* The analysis context, if any. Used to create an appropriate 'dart:async'
* library to back `Future<T>`.
*/
@@ -612,14 +607,6 @@
return _typeType;
}
- @override
- DartType get undefinedType {
- if (_undefinedType == null) {
- _undefinedType = UndefinedTypeImpl.instance;
- }
- return _undefinedType;
- }
-
void _initDartAsync() {
Source asyncSource;
if (_driver != null) {
diff --git a/pkg/analyzer/lib/src/summary/link.dart b/pkg/analyzer/lib/src/summary/link.dart
index 012a2ac..76eaf73 100644
--- a/pkg/analyzer/lib/src/summary/link.dart
+++ b/pkg/analyzer/lib/src/summary/link.dart
@@ -5481,9 +5481,6 @@
InterfaceType get typeType =>
_typeType ??= _buildInterfaceType(_linker.coreLibrary, 'Type');
- @override
- DartType get undefinedType => UndefinedTypeImpl.instance;
-
InterfaceType _buildInterfaceType(
LibraryElementForLink library, String name) {
return library.getContainedName(name).buildType((int i) {
diff --git a/pkg/analyzer/lib/src/summary/resynthesize.dart b/pkg/analyzer/lib/src/summary/resynthesize.dart
index 3c6b194..6f8720e 100644
--- a/pkg/analyzer/lib/src/summary/resynthesize.dart
+++ b/pkg/analyzer/lib/src/summary/resynthesize.dart
@@ -1491,7 +1491,7 @@
bool isDeclarableType = false;
int numTypeParameters = linkedReference.numTypeParameters;
if (linkedReference.kind == ReferenceKind.unresolved) {
- type = UndefinedTypeImpl.instance;
+ type = DynamicTypeImpl.instance;
element = null;
isDeclarableType = true;
} else if (name == 'dynamic') {
diff --git a/pkg/analyzer/lib/src/summary/summary_sdk.dart b/pkg/analyzer/lib/src/summary/summary_sdk.dart
index f31b076..28dc74a 100644
--- a/pkg/analyzer/lib/src/summary/summary_sdk.dart
+++ b/pkg/analyzer/lib/src/summary/summary_sdk.dart
@@ -349,9 +349,6 @@
return _typeType;
}
- @override
- DartType get undefinedType => UndefinedTypeImpl.instance;
-
/**
* Initialize the `dart:async` types provided by this type provider.
*/
diff --git a/pkg/analyzer/test/generated/checked_mode_compile_time_error_code_test.dart b/pkg/analyzer/test/generated/checked_mode_compile_time_error_code_test.dart
index 46f7960..4a01b55 100644
--- a/pkg/analyzer/test/generated/checked_mode_compile_time_error_code_test.dart
+++ b/pkg/analyzer/test/generated/checked_mode_compile_time_error_code_test.dart
@@ -227,10 +227,7 @@
const A(String this.x);
}
var v = const A('foo');
-''', [
- CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH,
- StaticWarningCode.UNDEFINED_CLASS
- ]);
+''', [StaticWarningCode.UNDEFINED_CLASS]);
}
test_fieldFormalParameterNotAssignableToField_implements() async {
@@ -362,10 +359,7 @@
final Unresolved y;
}
var v = const A('foo');
-''', [
- CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH,
- StaticWarningCode.UNDEFINED_CLASS
- ]);
+''', [StaticWarningCode.UNDEFINED_CLASS]);
}
test_fieldTypeOk_generic() async {
@@ -489,10 +483,7 @@
const A(Unresolved x);
}
var v = const A('foo');
-''', [
- CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH,
- StaticWarningCode.UNDEFINED_CLASS
- ]);
+''', [StaticWarningCode.UNDEFINED_CLASS]);
}
test_redirectingConstructor_paramTypeMismatch() async {
@@ -544,9 +535,6 @@
test_topLevelVarNotAssignable_undefined() async {
await assertErrorCodesInCode('''
const Unresolved x = 'foo';
-''', [
- CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH,
- StaticWarningCode.UNDEFINED_CLASS
- ]);
+''', [StaticWarningCode.UNDEFINED_CLASS]);
}
}
diff --git a/pkg/analyzer/test/generated/resolver_test.dart b/pkg/analyzer/test/generated/resolver_test.dart
index 9c5be7a..b7c7c60 100644
--- a/pkg/analyzer/test/generated/resolver_test.dart
+++ b/pkg/analyzer/test/generated/resolver_test.dart
@@ -1953,7 +1953,7 @@
..staticElement = new _StaleElement();
TypeName typeName = astFactory.typeName(id, null);
_resolveNode(typeName, []);
- expect(typeName.type, UndefinedTypeImpl.instance);
+ expect(typeName.type, DynamicTypeImpl.instance);
expect(typeName.name.staticElement, null);
_listener.assertErrorsWithCodes([StaticWarningCode.UNDEFINED_CLASS]);
}
@@ -1994,7 +1994,7 @@
TypeName typeName =
astFactory.typeName(AstTestFactory.identifier(prefix, suffix), null);
_resolveNode(typeName, []);
- expect(typeName.type, UndefinedTypeImpl.instance);
+ expect(typeName.type, DynamicTypeImpl.instance);
expect(prefix.staticElement, null);
expect(suffix.staticElement, null);
_listener.assertErrorsWithCodes([StaticWarningCode.UNDEFINED_CLASS]);
diff --git a/pkg/analyzer/test/src/dart/analysis/driver_resolution_test.dart b/pkg/analyzer/test/src/dart/analysis/driver_resolution_test.dart
index b116529..48504cb 100644
--- a/pkg/analyzer/test/src/dart/analysis/driver_resolution_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/driver_resolution_test.dart
@@ -35,8 +35,6 @@
final isDynamicType = new TypeMatcher<DynamicTypeImpl>();
-final isUndefinedType = new TypeMatcher<UndefinedTypeImpl>();
-
final isVoidType = new TypeMatcher<VoidTypeImpl>();
/**
@@ -1837,12 +1835,12 @@
VariableDeclarationStatement statement = statements[0];
TypeName typeName = statement.variables.type;
- expect(typeName.type, isUndefinedType);
+ expect(typeName.type, isDynamicType);
expect(typeName.typeArguments.arguments[0].type, typeProvider.intType);
VariableDeclaration vNode = statement.variables.variables[0];
- expect(vNode.name.staticType, isUndefinedType);
- expect(vNode.declaredElement.type, isUndefinedType);
+ expect(vNode.name.staticType, isDynamicType);
+ expect(vNode.declaredElement.type, isDynamicType);
}
test_field_context() async {
@@ -8095,7 +8093,6 @@
assertType(identifier, 'Type');
}
- @failingTest
test_unresolved_instanceCreation_name_11() async {
addTestFile(r'''
int arg1, arg2;
@@ -8226,12 +8223,12 @@
ExpressionStatement statement = statements[0];
InstanceCreationExpression creation = statement.expression;
- expect(creation.staticType, isUndefinedType);
+ expect(creation.staticType, isDynamicType);
ConstructorName constructorName = creation.constructorName;
TypeName typeName = constructorName.type;
- expect(typeName.type, isUndefinedType);
+ expect(typeName.type, isDynamicType);
PrefixedIdentifier typePrefixed = typeName.name;
assertElementNull(typePrefixed);
@@ -8273,12 +8270,12 @@
ExpressionStatement statement = statements[0];
InstanceCreationExpression creation = statement.expression;
- expect(creation.staticType, isUndefinedType);
+ expect(creation.staticType, isDynamicType);
ConstructorName constructorName = creation.constructorName;
TypeName typeName = constructorName.type;
- expect(typeName.type, isUndefinedType);
+ expect(typeName.type, isDynamicType);
PrefixedIdentifier typePrefixed = typeName.name;
assertElementNull(typePrefixed);
diff --git a/pkg/analyzer/test/src/dart/resolution/resolution.dart b/pkg/analyzer/test/src/dart/resolution/resolution.dart
index b713264..b7fb02f 100644
--- a/pkg/analyzer/test/src/dart/resolution/resolution.dart
+++ b/pkg/analyzer/test/src/dart/resolution/resolution.dart
@@ -26,8 +26,6 @@
final isDynamicType = new TypeMatcher<DynamicTypeImpl>();
-final isUndefinedType = new TypeMatcher<UndefinedTypeImpl>();
-
final isVoidType = new TypeMatcher<VoidTypeImpl>();
/// Base for resolution tests.