Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1067)

Unified Diff: pkg/compiler/lib/src/elements/resolution_types.dart

Issue 2944843002: All strong mode cleaning of dart2js. (Closed)
Patch Set: More issues discovered during testing. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/elements/modelx.dart ('k') | pkg/compiler/lib/src/elements/types.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/elements/resolution_types.dart
diff --git a/pkg/compiler/lib/src/elements/resolution_types.dart b/pkg/compiler/lib/src/elements/resolution_types.dart
index d37ef6be28ac0b1219f095fa8d70dd57ec52f8f1..050914f213915ed16236e086bd094dccd0f12310 100644
--- a/pkg/compiler/lib/src/elements/resolution_types.dart
+++ b/pkg/compiler/lib/src/elements/resolution_types.dart
@@ -59,8 +59,8 @@ abstract class ResolutionDartType implements DartType {
*
* Invariant: There must be the same number of [arguments] and [parameters].
*/
- ResolutionDartType subst(
- List<ResolutionDartType> arguments, List<ResolutionDartType> parameters);
+ ResolutionDartType subst(covariant List<ResolutionDartType> arguments,
+ covariant List<ResolutionDartType> parameters);
/// Performs the substitution of the type arguments of [type] for their
/// corresponding type variables in this type.
@@ -162,12 +162,13 @@ abstract class ResolutionDartType implements DartType {
return new TypeDeclarationFormatter().format(this, name);
}
- R accept<R, A>(ResolutionDartTypeVisitor<R, A> visitor, A argument);
+ R accept<R, A>(covariant ResolutionDartTypeVisitor<R, A> visitor, A argument);
- void visitChildren<R, A>(ResolutionDartTypeVisitor visitor, var argument) {}
+ void visitChildren<R, A>(
+ ResolutionDartTypeVisitor<R, A> visitor, A argument) {}
- static void visitList<R, A>(
- List<ResolutionDartType> types, DartTypeVisitor visitor, var argument) {
+ static void visitList<R, A>(List<ResolutionDartType> types,
+ ResolutionDartTypeVisitor<R, A> visitor, A argument) {
for (ResolutionDartType type in types) {
type.accept(visitor, argument);
}
@@ -216,8 +217,8 @@ class ResolutionTypeVariableType extends ResolutionDartType
String get name => element.name;
- ResolutionDartType subst(
- List<ResolutionDartType> arguments, List<ResolutionDartType> parameters) {
+ ResolutionDartType subst(covariant List<ResolutionDartType> arguments,
+ covariant List<ResolutionDartType> parameters) {
assert(arguments.length == parameters.length);
if (parameters.isEmpty) {
// Return fast on empty substitutions.
@@ -283,8 +284,8 @@ class ResolutionVoidType extends ResolutionDartType implements VoidType {
Element get element => null;
- ResolutionDartType subst(
- List<ResolutionDartType> arguments, List<ResolutionDartType> parameters) {
+ ResolutionDartType subst(covariant List<ResolutionDartType> arguments,
+ covariant List<ResolutionDartType> parameters) {
// Void cannot be substituted.
return this;
}
@@ -331,8 +332,8 @@ class MalformedType extends ResolutionDartType {
String get name => element.name;
- ResolutionDartType subst(
- List<ResolutionDartType> arguments, List<ResolutionDartType> parameters) {
+ ResolutionDartType subst(covariant List<ResolutionDartType> arguments,
+ covariant List<ResolutionDartType> parameters) {
// Malformed types are not substitutable.
return this;
}
@@ -343,7 +344,8 @@ class MalformedType extends ResolutionDartType {
@override
bool get isMalformed => true;
- R accept<R, A>(ResolutionDartTypeVisitor<R, A> visitor, A argument) {
+ R accept<R, A>(
+ covariant ResolutionDartTypeVisitor<R, A> visitor, A argument) {
return visitor.visitMalformedType(this, argument);
}
@@ -367,8 +369,7 @@ class MalformedType extends ResolutionDartType {
}
}
-abstract class GenericType<T extends GenericType<T>>
- extends ResolutionDartType {
+abstract class GenericType extends ResolutionDartType {
final TypeDeclarationElement element;
final List<ResolutionDartType> typeArguments;
@@ -398,10 +399,10 @@ abstract class GenericType<T extends GenericType<T>>
}
/// Creates a new instance of this type using the provided type arguments.
- T createInstantiation(List<ResolutionDartType> newTypeArguments);
+ GenericType createInstantiation(List<ResolutionDartType> newTypeArguments);
- T subst(
- List<ResolutionDartType> arguments, List<ResolutionDartType> parameters) {
+ GenericType subst(covariant List<ResolutionDartType> arguments,
+ covariant List<ResolutionDartType> parameters) {
if (typeArguments.isEmpty) {
// Return fast on non-generic types.
return this;
@@ -430,7 +431,8 @@ abstract class GenericType<T extends GenericType<T>>
}
}
- void visitChildren(DartTypeVisitor visitor, var argument) {
+ void visitChildren<R, A>(
+ ResolutionDartTypeVisitor<R, A> visitor, var argument) {
ResolutionDartType.visitList(typeArguments, visitor, argument);
}
@@ -489,9 +491,7 @@ abstract class GenericType<T extends GenericType<T>>
}
}
-// ignore: INCONSISTENT_METHOD_INHERITANCE
-class ResolutionInterfaceType extends GenericType<ResolutionInterfaceType>
- implements InterfaceType {
+class ResolutionInterfaceType extends GenericType implements InterfaceType {
int _hashCode;
ResolutionInterfaceType(ClassElement element,
@@ -565,6 +565,11 @@ class ResolutionInterfaceType extends GenericType<ResolutionInterfaceType>
ResolutionFunctionType type = element.callType;
return type != null && isGeneric ? type.substByContext(this) : type;
}
+
+ ResolutionInterfaceType subst(covariant List<ResolutionDartType> arguments,
+ covariant List<ResolutionDartType> parameters) {
+ return super.subst(arguments, parameters);
+ }
}
/// Special subclass of [ResolutionInterfaceType] used for generic interface
@@ -696,8 +701,8 @@ class ResolutionFunctionType extends ResolutionDartType
return null;
}
- ResolutionDartType subst(
- List<ResolutionDartType> arguments, List<ResolutionDartType> parameters) {
+ ResolutionDartType subst(covariant List<ResolutionDartType> arguments,
+ covariant List<ResolutionDartType> parameters) {
if (parameters.isEmpty) {
assert(arguments.isEmpty);
// Return fast on empty substitutions.
@@ -757,11 +762,12 @@ class ResolutionFunctionType extends ResolutionDartType
});
}
- R accept<R, A>(DartTypeVisitor<R, A> visitor, A argument) {
+ R accept<R, A>(covariant DartTypeVisitor<R, A> visitor, A argument) {
return visitor.visitFunctionType(this, argument);
}
- void visitChildren(DartTypeVisitor visitor, var argument) {
+ void visitChildren<R, A>(
+ ResolutionDartTypeVisitor<R, A> visitor, var argument) {
returnType.accept(visitor, argument);
ResolutionDartType.visitList(parameterTypes, visitor, argument);
ResolutionDartType.visitList(optionalParameterTypes, visitor, argument);
@@ -860,7 +866,7 @@ class ResolutionFunctionType extends ResolutionDartType
bool _typeContainsMethodTypeVariableType(ResolutionDartType type) =>
type.containsMethodTypeVariableType;
-class ResolutionTypedefType extends GenericType<ResolutionTypedefType> {
+class ResolutionTypedefType extends GenericType {
ResolutionDartType _unaliased;
ResolutionTypedefType(TypedefElement element,
@@ -907,7 +913,8 @@ class ResolutionTypedefType extends GenericType<ResolutionTypedefType> {
ResolutionTypedefType asRaw() => super.asRaw();
- R accept<R, A>(ResolutionDartTypeVisitor<R, A> visitor, A argument) {
+ R accept<R, A>(
+ covariant ResolutionDartTypeVisitor<R, A> visitor, A argument) {
return visitor.visitTypedefType(this, argument);
}
}
@@ -926,8 +933,8 @@ class ResolutionDynamicType extends ResolutionDartType implements DynamicType {
ResolutionTypeKind get kind => ResolutionTypeKind.DYNAMIC;
- ResolutionDartType subst(List<ResolutionDartType> arguments,
- List<ResolutionDartType> parameters) =>
+ ResolutionDartType subst(covariant List<ResolutionDartType> arguments,
+ covariant List<ResolutionDartType> parameters) =>
this;
R accept<R, A>(DartTypeVisitor<R, A> visitor, A argument) {
@@ -1000,7 +1007,7 @@ abstract class BaseResolutionDartTypeVisitor<R, A>
R visitGenericType(GenericType type, A argument) => visitType(type, argument);
@override
- R visitInterfaceType(ResolutionInterfaceType type, A argument) =>
+ R visitInterfaceType(covariant ResolutionInterfaceType type, A argument) =>
visitGenericType(type, argument);
@override
@@ -1009,33 +1016,38 @@ abstract class BaseResolutionDartTypeVisitor<R, A>
}
abstract class AbstractTypeRelationMixin
- implements AbstractTypeRelation, ResolutionDartTypeVisitor<bool, DartType> {
+ implements
+ AbstractTypeRelation<ResolutionDartType>,
+ ResolutionDartTypeVisitor<bool, ResolutionDartType> {
Resolution get resolution;
@override
CommonElements get commonElements => resolution.commonElements;
/// Ensures that the super hierarchy of [type] is computed.
- void ensureResolved(ResolutionInterfaceType type) {
+ void ensureResolved(covariant ResolutionInterfaceType type) {
// TODO(johnniwinther): Currently needed since literal types like int,
// double, bool etc. might not have been resolved yet.
type.element.ensureResolved(resolution);
}
/// Returns the unaliased version of [type].
- DartType getUnaliased(ResolutionDartType type) {
+ ResolutionDartType getUnaliased(covariant ResolutionDartType type) {
type.computeUnaliased(resolution);
return type.unaliased;
}
@override
- DartType getTypeVariableBound(TypeVariableElement element) => element.bound;
+ DartType getTypeVariableBound(covariant TypeVariableElement element) =>
+ element.bound;
@override
- FunctionType getCallType(ResolutionInterfaceType type) => type.callType;
+ FunctionType getCallType(covariant ResolutionInterfaceType type) =>
+ type.callType;
@override
- InterfaceType asInstanceOf(ResolutionInterfaceType type, ClassEntity cls) =>
+ InterfaceType asInstanceOf(
+ covariant ResolutionInterfaceType type, ClassEntity cls) =>
type.asInstanceOf(cls);
/// Handle as dynamic for both subtype and more specific relation to avoid
@@ -1046,21 +1058,23 @@ abstract class AbstractTypeRelationMixin
visitType(t, s);
}
-class ResolutionMoreSpecificVisitor extends MoreSpecificVisitor
+class ResolutionMoreSpecificVisitor
+ extends MoreSpecificVisitor<ResolutionDartType>
with AbstractTypeRelationMixin {
final Resolution resolution;
ResolutionMoreSpecificVisitor(this.resolution);
}
-class ResolutionSubtypeVisitor extends SubtypeVisitor
+class ResolutionSubtypeVisitor extends SubtypeVisitor<ResolutionDartType>
with AbstractTypeRelationMixin {
final Resolution resolution;
ResolutionSubtypeVisitor(this.resolution);
}
-class ResolutionPotentialSubtypeVisitor extends PotentialSubtypeVisitor
+class ResolutionPotentialSubtypeVisitor
+ extends PotentialSubtypeVisitor<ResolutionDartType>
with AbstractTypeRelationMixin {
final Resolution resolution;
@@ -1072,8 +1086,8 @@ class ResolutionPotentialSubtypeVisitor extends PotentialSubtypeVisitor
* substitute for the bound of [typeVariable]. [bound] holds the bound against
* which [typeArgument] should be checked.
*/
-typedef void CheckTypeVariableBound<T extends GenericType>(T type,
- DartType typeArgument, TypeVariableType typeVariable, DartType bound);
+typedef void CheckTypeVariableBound(GenericType type, DartType typeArgument,
+ TypeVariableType typeVariable, DartType bound);
class Types extends DartTypes {
final Resolution resolution;
@@ -1098,35 +1112,34 @@ class Types extends DartTypes {
}
@override
- InterfaceType asInstanceOf(ResolutionInterfaceType type, ClassEntity cls) {
+ InterfaceType asInstanceOf(
+ covariant ResolutionInterfaceType type, ClassEntity cls) {
return type.asInstanceOf(cls);
}
@override
- ResolutionDartType substByContext(
- ResolutionDartType base, ResolutionInterfaceType context) {
+ ResolutionDartType substByContext(covariant ResolutionDartType base,
+ covariant ResolutionInterfaceType context) {
return base.substByContext(context);
}
@override
- InterfaceType getThisType(ClassElement cls) {
- return cls.thisType;
- }
+ InterfaceType getThisType(covariant ClassElement cls) => cls.thisType;
@override
- ResolutionInterfaceType getSupertype(ClassElement cls) {
- return cls.supertype;
- }
+ ResolutionInterfaceType getSupertype(covariant ClassElement cls) =>
+ cls.supertype;
@override
- Iterable<InterfaceType> getSupertypes(ClassElement cls) {
+ Iterable<InterfaceType> getSupertypes(covariant ClassElement cls) {
assert(cls.allSupertypes != null,
failedAt(cls, 'Supertypes have not been computed for $cls.'));
return cls.allSupertypes;
}
@override
- FunctionType getCallType(ResolutionInterfaceType type) => type.callType;
+ FunctionType getCallType(covariant ResolutionInterfaceType type) =>
+ type.callType;
/// Flatten [type] by recursively removing enclosing `Future` annotations.
///
@@ -1179,15 +1192,18 @@ class Types extends DartTypes {
}
/** Returns true if t is a subtype of s */
- bool isSubtype(ResolutionDartType t, ResolutionDartType s) {
+ bool isSubtype(
+ covariant ResolutionDartType t, covariant ResolutionDartType s) {
return subtypeVisitor.isSubtype(t, s);
}
- bool isAssignable(ResolutionDartType r, ResolutionDartType s) {
+ bool isAssignable(
+ covariant ResolutionDartType r, covariant ResolutionDartType s) {
return subtypeVisitor.isAssignable(r, s);
}
- bool isPotentialSubtype(ResolutionDartType t, ResolutionDartType s) {
+ bool isPotentialSubtype(
+ covariant ResolutionDartType t, covariant ResolutionDartType s) {
// TODO(johnniwinther): Return a set of variable points in the positive
// cases.
return potentialSubtypeVisitor.isSubtype(t, s);
@@ -1195,10 +1211,13 @@ class Types extends DartTypes {
@override
void checkTypeVariableBounds(
- ResolutionInterfaceType type,
+ covariant ResolutionInterfaceType type,
void checkTypeVariableBound(InterfaceType type, DartType typeArgument,
TypeVariableType typeVariable, DartType bound)) {
- genericCheckTypeVariableBounds(type, checkTypeVariableBound);
+ void f(DartType type, DartType typeArgument, TypeVariableType typeVariable,
+ DartType bound) =>
+ checkTypeVariableBound(type, typeArgument, typeVariable, bound);
+ genericCheckTypeVariableBounds(type, f);
}
/**
@@ -1206,8 +1225,8 @@ class Types extends DartTypes {
* declared on [element]. Calls [checkTypeVariableBound] on each type
* argument and bound.
*/
- void genericCheckTypeVariableBounds<T extends GenericType>(
- T type, CheckTypeVariableBound<T> checkTypeVariableBound) {
+ void genericCheckTypeVariableBounds(
+ GenericType type, CheckTypeVariableBound checkTypeVariableBound) {
TypeDeclarationElement element = type.element;
List<ResolutionDartType> typeArguments = type.typeArguments;
List<ResolutionDartType> typeVariables = element.typeVariables;
@@ -1653,7 +1672,8 @@ class MoreSpecificSubtypeVisitor
return null;
}
- bool visitType(ResolutionDartType type, ResolutionDartType argument) {
+ bool visitType(
+ covariant ResolutionDartType type, ResolutionDartType argument) {
return types.isMoreSpecific(type, argument);
}
@@ -1666,7 +1686,7 @@ class MoreSpecificSubtypeVisitor
}
bool visitTypeVariableType(
- ResolutionTypeVariableType type, ResolutionDartType argument) {
+ covariant ResolutionTypeVariableType type, ResolutionDartType argument) {
ResolutionDartType constraint =
types.getMostSpecific(constraintMap[type], argument);
constraintMap[type] = constraint;
@@ -1674,7 +1694,7 @@ class MoreSpecificSubtypeVisitor
}
bool visitFunctionType(
- ResolutionFunctionType type, ResolutionDartType argument) {
+ covariant ResolutionFunctionType type, ResolutionDartType argument) {
if (argument is ResolutionFunctionType) {
if (type.parameterTypes.length != argument.parameterTypes.length) {
return false;
@@ -1741,7 +1761,7 @@ class TypeDeclarationFormatter
return proposal;
}
- void visit(ResolutionDartType type, [_]) {
+ void visit(covariant ResolutionDartType type, [_]) {
type.accept(this, null);
}
@@ -1756,7 +1776,7 @@ class TypeDeclarationFormatter
}
}
- void visitType(ResolutionDartType type, String name) {
+ void visitType(covariant ResolutionDartType type, String name) {
if (name == null) {
sb.write(type);
} else {
@@ -1777,7 +1797,7 @@ class TypeDeclarationFormatter
}
}
- void visitFunctionType(ResolutionFunctionType type, String name) {
+ void visitFunctionType(covariant ResolutionFunctionType type, String name) {
visit(type.returnType);
sb.write(' ');
if (name != null) {
« no previous file with comments | « pkg/compiler/lib/src/elements/modelx.dart ('k') | pkg/compiler/lib/src/elements/types.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698