| Index: pkg/compiler/lib/src/dart_types.dart
|
| diff --git a/pkg/compiler/lib/src/dart_types.dart b/pkg/compiler/lib/src/dart_types.dart
|
| index 685077d0b6380f328b351f118f8e5157f45b29d2..0873c556d3d6115c00877bdd6e93b19269b31f1b 100644
|
| --- a/pkg/compiler/lib/src/dart_types.dart
|
| +++ b/pkg/compiler/lib/src/dart_types.dart
|
| @@ -164,6 +164,15 @@ abstract class DartType {
|
| type.accept(visitor, argument);
|
| }
|
| }
|
| +
|
| + /// Returns a [DartType] which corresponds to [this] except that each
|
| + /// contained [MethodTypeVariableType] is replaced by a [DynamicType].
|
| + /// GENERIC_METHODS: Temporary, only used with '--generic-method-syntax'.
|
| + DartType get eraseMethodTypeVariableType => this;
|
| +
|
| + /// Returns true iff [this] is or contains a [MethodTypeVariableType].
|
| + /// GENERIC_METHODS: Temporary, only used with '--generic-method-syntax'
|
| + bool get containsMethodTypeVariableType => false;
|
| }
|
|
|
| /**
|
| @@ -234,6 +243,22 @@ class TypeVariableType extends DartType {
|
| String toString() => name;
|
| }
|
|
|
| +/// Provides a thin model of method type variables: They are treated as if
|
| +/// their value were `dynamic` when used in a type annotation, and as a
|
| +/// malformed type when used in an `as` or `is` expression.
|
| +class MethodTypeVariableType extends TypeVariableType {
|
| + MethodTypeVariableType(TypeVariableElement element) : super(element);
|
| +
|
| + @override
|
| + bool get treatAsDynamic => true;
|
| +
|
| + @override
|
| + DartType get eraseMethodTypeVariableType => const DynamicType();
|
| +
|
| + @override
|
| + get containsMethodTypeVariableType => true;
|
| +}
|
| +
|
| /// Internal type representing the result of analyzing a statement.
|
| class StatementType extends DartType {
|
| Element get element => null;
|
| @@ -405,6 +430,12 @@ abstract class GenericType extends DartType {
|
| return sb.toString();
|
| }
|
|
|
| + @override
|
| + bool get containsMethodTypeVariableType {
|
| + return typeArguments.any(
|
| + (DartType type) => type.containsMethodTypeVariableType);
|
| + }
|
| +
|
| int get hashCode {
|
| int hash = element.hashCode;
|
| for (DartType argument in typeArguments) {
|
| @@ -496,6 +527,14 @@ class InterfaceType extends GenericType {
|
| return member;
|
| }
|
|
|
| + @override
|
| + DartType get eraseMethodTypeVariableType {
|
| + if (!containsMethodTypeVariableType) return this;
|
| + List<DartType> newTypeArguments = typeArguments.map(
|
| + (DartType type) => type.eraseMethodTypeVariableType).toList();
|
| + return new InterfaceType(element, newTypeArguments);
|
| + }
|
| +
|
| int get hashCode => _hashCode ??= super.hashCode;
|
|
|
| InterfaceType asRaw() => super.asRaw();
|
| @@ -718,6 +757,34 @@ class FunctionType extends DartType {
|
|
|
| int computeArity() => parameterTypes.length;
|
|
|
| + @override
|
| + DartType get eraseMethodTypeVariableType {
|
| + if (!containsMethodTypeVariableType) return this;
|
| + DartType eraseIt(DartType type) => type.eraseMethodTypeVariableType;
|
| + DartType newReturnType = returnType.eraseMethodTypeVariableType;
|
| + List<DartType> newParameterTypes = parameterTypes.map(eraseIt).toList();
|
| + List<DartType> newOptionalParameterTypes =
|
| + optionalParameterTypes.map(eraseIt).toList();
|
| + List<DartType> newNamedParameterTypes =
|
| + namedParameterTypes.map(eraseIt).toList();
|
| + return new FunctionType.internal(
|
| + element,
|
| + newReturnType,
|
| + newParameterTypes,
|
| + newOptionalParameterTypes,
|
| + namedParameters,
|
| + newNamedParameterTypes);
|
| + }
|
| +
|
| + @override
|
| + bool get containsMethodTypeVariableType {
|
| + bool containsIt(DartType type) => type.containsMethodTypeVariableType;
|
| + return returnType.containsMethodTypeVariableType ||
|
| + parameterTypes.any(containsIt) ||
|
| + optionalParameterTypes.any(containsIt) ||
|
| + namedParameterTypes.any(containsIt);
|
| + }
|
| +
|
| int get hashCode {
|
| int hash = 3 * returnType.hashCode;
|
| for (DartType parameter in parameterTypes) {
|
| @@ -1347,6 +1414,15 @@ class Types implements DartTypes {
|
| static ClassElement getClassContext(DartType type) {
|
| TypeVariableType typeVariable = type.typeVariableOccurrence;
|
| if (typeVariable == null) return null;
|
| + // GENERIC_METHODS: When generic method support is complete enough to
|
| + // include a runtime value for method type variables this must be updated.
|
| + // For full support the global assumption that all type variables are
|
| + // declared by the same enclosing class will not hold: Both an enclosing
|
| + // method and an enclosing class may define type variables, so the return
|
| + // type cannot be [ClassElement] and the caller must be prepared to look in
|
| + // two locations, not one. Currently we ignore method type variables by
|
| + // returning in the next statement.
|
| + if (typeVariable.element.typeDeclaration is! ClassElement) return null;
|
| return typeVariable.element.typeDeclaration;
|
| }
|
|
|
|
|