Skip to content

Commit a01c3b4

Browse files
committed
Use TypeParameterElement(s) as free variables in FunctionType.toString().
Types should have never been used here in the first place. And with nullability we get mismatches where type parameters are used with a suffix :-( Change-Id: I93ff61ee9bf32c24cdf3d2aadeb23cbb84b34cfa Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/124501 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
1 parent 9c4c49d commit a01c3b4

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

pkg/analyzer/lib/src/dart/element/type.dart

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,12 @@ class FunctionTypeImpl extends TypeImpl implements FunctionType {
291291
StringBuffer typeParametersBuffer = StringBuffer();
292292
// To print a type with type variables, first make sure we have unique
293293
// variable names to print.
294-
Set<TypeParameterType> freeVariables = new HashSet<TypeParameterType>();
294+
var freeVariables = <TypeParameterElement>{};
295295
_freeVariablesInFunctionType(this, freeVariables);
296296

297-
Set<String> namesToAvoid = new HashSet<String>();
298-
for (DartType arg in freeVariables) {
299-
if (arg is TypeParameterType) {
300-
namesToAvoid.add(arg.displayName);
301-
}
297+
var namesToAvoid = <String>{};
298+
for (TypeParameterElement arg in freeVariables) {
299+
namesToAvoid.add(arg.displayName);
302300
}
303301

304302
List<DartType> instantiateTypeArgs = <DartType>[];
@@ -525,35 +523,24 @@ class FunctionTypeImpl extends TypeImpl implements FunctionType {
525523
}
526524

527525
void _freeVariablesInFunctionType(
528-
FunctionType type, Set<TypeParameterType> free) {
529-
// Make some fresh variables to avoid capture.
530-
List<DartType> typeArgs = const <DartType>[];
531-
if (type.typeFormals.isNotEmpty) {
532-
typeArgs = new List<DartType>.from(type.typeFormals.map((e) =>
533-
new TypeParameterTypeImpl(new TypeParameterElementImpl(e.name, -1))));
534-
535-
type = type.instantiate(typeArgs);
536-
}
537-
538-
for (ParameterElement p in type.parameters) {
539-
_freeVariablesInType(p.type, free);
526+
FunctionType type, Set<TypeParameterElement> free) {
527+
for (var parameter in type.parameters) {
528+
_freeVariablesInType(parameter.type, free);
540529
}
541530
_freeVariablesInType(type.returnType, free);
542-
543-
// Remove all of our bound variables.
544-
free.removeAll(typeArgs);
531+
free.removeAll(type.typeFormals);
545532
}
546533

547534
void _freeVariablesInInterfaceType(
548-
InterfaceType type, Set<TypeParameterType> free) {
535+
InterfaceType type, Set<TypeParameterElement> free) {
549536
for (DartType typeArg in type.typeArguments) {
550537
_freeVariablesInType(typeArg, free);
551538
}
552539
}
553540

554-
void _freeVariablesInType(DartType type, Set<TypeParameterType> free) {
541+
void _freeVariablesInType(DartType type, Set<TypeParameterElement> free) {
555542
if (type is TypeParameterType) {
556-
free.add(type);
543+
free.add(type.element);
557544
} else if (type is FunctionType) {
558545
_freeVariablesInFunctionType(type, free);
559546
} else if (type is InterfaceType) {

0 commit comments

Comments
 (0)