Include type arguments for non-synthetic FunctionTypeImpl(s) into displayName.

R=brianwilkerson@google.com
BUG=

Review-Url: https://codereview.chromium.org/2762743002 .
This commit is contained in:
Konstantin Shcheglov 2017-03-20 13:18:05 -07:00
parent 15f393f189
commit 82751915c1
2 changed files with 66 additions and 33 deletions

View file

@ -454,13 +454,42 @@ class FunctionTypeImpl extends TypeImpl implements FunctionType {
@override
String get displayName {
String name = this.name;
// Function types have an empty name when they are defined implicitly by
// either a closure or as part of a parameter declaration.
if (name == null || name.length == 0) {
// Function types have an empty name when they are defined implicitly by
// either a closure or as part of a parameter declaration.
StringBuffer buffer = new StringBuffer();
appendTo(buffer, new Set.identity());
return buffer.toString();
}
List<DartType> typeArguments = this.typeArguments;
bool areAllTypeArgumentsDynamic() {
for (DartType type in typeArguments) {
if (type != null && !type.isDynamic) {
return false;
}
}
return true;
}
// If there is at least one non-dynamic type, then list them out.
if (!areAllTypeArgumentsDynamic()) {
StringBuffer buffer = new StringBuffer();
buffer.write(name);
buffer.write("<");
for (int i = 0; i < typeArguments.length; i++) {
if (i != 0) {
buffer.write(", ");
}
DartType typeArg = typeArguments[i];
buffer.write(typeArg.displayName);
}
buffer.write(">");
name = buffer.toString();
}
return name;
}
@ -1379,16 +1408,20 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
@override
String get displayName {
String name = this.name;
List<DartType> typeArguments = this.typeArguments;
bool allDynamic = true;
for (DartType type in typeArguments) {
if (type != null && !type.isDynamic) {
allDynamic = false;
break;
bool areAllTypeArgumentsDynamic() {
for (DartType type in typeArguments) {
if (type != null && !type.isDynamic) {
return false;
}
}
return true;
}
// If there is at least one non-dynamic type, then list them out
if (!allDynamic) {
// If there is at least one non-dynamic type, then list them out.
if (!areAllTypeArgumentsDynamic()) {
StringBuffer buffer = new StringBuffer();
buffer.write(name);
buffer.write("<");
@ -2641,6 +2674,10 @@ abstract class TypeImpl implements DartType {
* A concrete implementation of a [TypeParameterType].
*/
class TypeParameterTypeImpl extends TypeImpl implements TypeParameterType {
static bool _comparingBounds = false;
static bool _appendingBounds = false;
/**
* Initialize a newly created type parameter type to be declared by the given
* [element] and to have the given name.
@ -2660,6 +2697,23 @@ class TypeParameterTypeImpl extends TypeImpl implements TypeParameterType {
@override
int get hashCode => element.hashCode;
@override
bool operator ==(Object other) {
if (other is TypeParameterTypeImpl && element == other.element) {
if (_comparingBounds) {
// If we're comparing bounds already, then we only need type variable
// equality.
return true;
}
_comparingBounds = true;
try {
return bound == other.bound;
} finally {
_comparingBounds = false;
}
}
return false;
}
/**
* Append a textual representation of this type to the given [buffer]. The set
* of [visitedTypes] is used to prevent infinite recursion.
@ -2681,27 +2735,6 @@ class TypeParameterTypeImpl extends TypeImpl implements TypeParameterType {
}
}
@override
bool operator ==(Object other) {
if (other is TypeParameterTypeImpl && element == other.element) {
if (_comparingBounds) {
// If we're comparing bounds already, then we only need type variable
// equality.
return true;
}
_comparingBounds = true;
try {
return bound == other.bound;
} finally {
_comparingBounds = false;
}
}
return false;
}
static bool _comparingBounds = false;
static bool _appendingBounds = false;
@override
bool isMoreSpecificThan(DartType s,
[bool withDynamic = false, Set<Element> visitedElements]) {

View file

@ -9768,7 +9768,7 @@ F f;
library,
r'''
typedef dynamic F<T extends num>(T p);
F f;
F<num> f;
''');
} else {
checkElementText(
@ -13715,14 +13715,14 @@ F f;
library,
r'''
typedef U F<T, U>(T t);
F f;
F<int, String> f;
''');
} else {
checkElementText(
library,
r'''
typedef U F<T, U>(T t);
F f;
F<int, String> f;
''');
}
}