Skip to content

Commit c17aff8

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Restore skipping all dynamic type arguments in DartType.displayName
There is one internal client that currently depends on such presentation. This will unblock rolling analyzer, then we will fix the client, and remove this skipping code in analyzer. R=brianwilkerson@google.com, paulberry@google.com Change-Id: I0d6387892d12326d658800069dd8a60faa589405 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127488 Reviewed-by: Paul Berry <paulberry@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
1 parent acac2d8 commit c17aff8

File tree

6 files changed

+128
-31
lines changed

6 files changed

+128
-31
lines changed

pkg/analyzer/lib/error/listener.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,11 @@ class ErrorReporter {
202202
if (name != null && name.isNotEmpty) {
203203
StringBuffer buffer = StringBuffer();
204204
buffer.write(name);
205-
(type as TypeImpl).appendTo(buffer, withNullability: false);
205+
(type as TypeImpl).appendTo(
206+
buffer,
207+
withNullability: false,
208+
skipAllDynamicArguments: false,
209+
);
206210
return buffer.toString();
207211
}
208212
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4634,7 +4634,11 @@ class GenericFunctionTypeElementImpl extends ElementImpl
46344634
void appendTo(StringBuffer buffer) {
46354635
DartType type = returnType;
46364636
if (type is TypeImpl) {
4637-
type.appendTo(buffer, withNullability: false);
4637+
type.appendTo(
4638+
buffer,
4639+
withNullability: false,
4640+
skipAllDynamicArguments: false,
4641+
);
46384642
buffer.write(' Function');
46394643
} else {
46404644
buffer.write('Function');

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

Lines changed: 110 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ class DynamicTypeImpl extends TypeImpl {
6565
bool operator ==(Object object) => identical(object, this);
6666

6767
@override
68-
void appendTo(StringBuffer buffer, {@required bool withNullability}) {
68+
void appendTo(
69+
StringBuffer buffer, {
70+
@required bool withNullability,
71+
@required bool skipAllDynamicArguments,
72+
}) {
6973
buffer.write('dynamic');
7074
}
7175

@@ -255,7 +259,11 @@ class FunctionTypeImpl extends TypeImpl implements FunctionType {
255259
}
256260

257261
@override
258-
void appendTo(StringBuffer buffer, {@required bool withNullability}) {
262+
void appendTo(
263+
StringBuffer buffer, {
264+
@required bool withNullability,
265+
@required bool skipAllDynamicArguments,
266+
}) {
259267
if (typeFormals.isNotEmpty) {
260268
StringBuffer typeParametersBuffer = StringBuffer();
261269
// To print a type with type variables, first make sure we have unique
@@ -296,25 +304,41 @@ class FunctionTypeImpl extends TypeImpl implements FunctionType {
296304
TypeParameterTypeImpl t = TypeParameterTypeImpl(
297305
TypeParameterElementImpl(name, -1),
298306
nullabilitySuffix: NullabilitySuffix.none);
299-
t.appendTo(typeParametersBuffer, withNullability: withNullability);
307+
t.appendTo(
308+
typeParametersBuffer,
309+
withNullability: withNullability,
310+
skipAllDynamicArguments: skipAllDynamicArguments,
311+
);
300312
instantiateTypeArgs.add(t);
301313
variables.add(e);
302314
if (e.bound != null) {
303315
typeParametersBuffer.write(' extends ');
304316
TypeImpl renamed =
305317
Substitution.fromPairs(variables, instantiateTypeArgs)
306318
.substituteType(e.bound);
307-
renamed.appendTo(typeParametersBuffer,
308-
withNullability: withNullability);
319+
renamed.appendTo(
320+
typeParametersBuffer,
321+
withNullability: withNullability,
322+
skipAllDynamicArguments: skipAllDynamicArguments,
323+
);
309324
}
310325
}
311326
typeParametersBuffer.write('>');
312327

313328
// Instantiate it and print the resulting type.
314329
this.instantiate(instantiateTypeArgs)._appendToWithTypeParameters(
315-
buffer, withNullability, typeParametersBuffer.toString());
330+
buffer,
331+
typeParametersBuffer.toString(),
332+
withNullability: withNullability,
333+
skipAllDynamicArguments: skipAllDynamicArguments,
334+
);
316335
} else {
317-
_appendToWithTypeParameters(buffer, withNullability, '');
336+
_appendToWithTypeParameters(
337+
buffer,
338+
'',
339+
withNullability: withNullability,
340+
skipAllDynamicArguments: skipAllDynamicArguments,
341+
);
318342
}
319343
}
320344

@@ -415,16 +439,23 @@ class FunctionTypeImpl extends TypeImpl implements FunctionType {
415439
}
416440

417441
void _appendToWithTypeParameters(
418-
StringBuffer buffer, bool withNullability, String typeParameters) {
442+
StringBuffer buffer,
443+
String typeParameters, {
444+
@required bool withNullability,
445+
@required bool skipAllDynamicArguments,
446+
}) {
419447
List<DartType> normalParameterTypes = this.normalParameterTypes;
420448
List<DartType> optionalParameterTypes = this.optionalParameterTypes;
421449
DartType returnType = this.returnType;
422450

423451
if (returnType == null) {
424452
buffer.write('null');
425453
} else {
426-
(returnType as TypeImpl)
427-
.appendTo(buffer, withNullability: withNullability);
454+
(returnType as TypeImpl).appendTo(
455+
buffer,
456+
withNullability: withNullability,
457+
skipAllDynamicArguments: skipAllDynamicArguments,
458+
);
428459
}
429460
buffer.write(' Function');
430461
buffer.write(typeParameters);
@@ -449,15 +480,23 @@ class FunctionTypeImpl extends TypeImpl implements FunctionType {
449480
if (normalParameterTypes.isNotEmpty) {
450481
for (DartType type in normalParameterTypes) {
451482
writeSeparator();
452-
(type as TypeImpl).appendTo(buffer, withNullability: withNullability);
483+
(type as TypeImpl).appendTo(
484+
buffer,
485+
withNullability: withNullability,
486+
skipAllDynamicArguments: skipAllDynamicArguments,
487+
);
453488
}
454489
}
455490
if (optionalParameterTypes.isNotEmpty) {
456491
startOptionalParameters();
457492
buffer.write('[');
458493
for (DartType type in optionalParameterTypes) {
459494
writeSeparator();
460-
(type as TypeImpl).appendTo(buffer, withNullability: withNullability);
495+
(type as TypeImpl).appendTo(
496+
buffer,
497+
withNullability: withNullability,
498+
skipAllDynamicArguments: skipAllDynamicArguments,
499+
);
461500
}
462501
buffer.write(']');
463502
needsComma = true;
@@ -474,8 +513,11 @@ class FunctionTypeImpl extends TypeImpl implements FunctionType {
474513
}
475514
buffer.write(parameter.name);
476515
buffer.write(': ');
477-
(parameter.type as TypeImpl)
478-
.appendTo(buffer, withNullability: withNullability);
516+
(parameter.type as TypeImpl).appendTo(
517+
buffer,
518+
withNullability: withNullability,
519+
skipAllDynamicArguments: skipAllDynamicArguments,
520+
);
479521
}
480522
buffer.write('}');
481523
needsComma = true;
@@ -1099,17 +1141,33 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
10991141
}
11001142

11011143
@override
1102-
void appendTo(StringBuffer buffer, {@required bool withNullability}) {
1144+
void appendTo(
1145+
StringBuffer buffer, {
1146+
@required bool withNullability,
1147+
@required bool skipAllDynamicArguments,
1148+
}) {
11031149
buffer.write(element.name);
1150+
11041151
int argumentCount = typeArguments.length;
1105-
if (argumentCount > 0) {
1152+
1153+
bool includeTypeArguments;
1154+
if (skipAllDynamicArguments) {
1155+
includeTypeArguments = typeArguments.any((t) => !t.isDynamic);
1156+
} else {
1157+
includeTypeArguments = argumentCount > 0;
1158+
}
1159+
1160+
if (includeTypeArguments) {
11061161
buffer.write("<");
11071162
for (int i = 0; i < argumentCount; i++) {
11081163
if (i > 0) {
11091164
buffer.write(", ");
11101165
}
1111-
(typeArguments[i] as TypeImpl)
1112-
.appendTo(buffer, withNullability: withNullability);
1166+
(typeArguments[i] as TypeImpl).appendTo(
1167+
buffer,
1168+
withNullability: withNullability,
1169+
skipAllDynamicArguments: skipAllDynamicArguments,
1170+
);
11131171
}
11141172
buffer.write(">");
11151173
}
@@ -1825,7 +1883,11 @@ class NeverTypeImpl extends TypeImpl {
18251883
bool operator ==(Object object) => identical(object, this);
18261884

18271885
@override
1828-
void appendTo(StringBuffer buffer, {@required bool withNullability}) {
1886+
void appendTo(
1887+
StringBuffer buffer, {
1888+
@required bool withNullability,
1889+
@required bool skipAllDynamicArguments,
1890+
}) {
18291891
buffer.write('Never');
18301892
if (withNullability) {
18311893
_appendNullability(buffer);
@@ -1892,9 +1954,13 @@ abstract class TypeImpl implements DartType {
18921954
*/
18931955
TypeImpl(this._element, this.name);
18941956

1957+
@deprecated
18951958
@override
18961959
String get displayName {
1897-
return getDisplayString(withNullability: false);
1960+
return getDisplayString(
1961+
withNullability: false,
1962+
skipAllDynamicArguments: true,
1963+
);
18981964
}
18991965

19001966
@override
@@ -1960,12 +2026,23 @@ abstract class TypeImpl implements DartType {
19602026
/**
19612027
* Append a textual representation of this type to the given [buffer].
19622028
*/
1963-
void appendTo(StringBuffer buffer, {@required bool withNullability});
2029+
void appendTo(
2030+
StringBuffer buffer, {
2031+
@required bool withNullability,
2032+
@required bool skipAllDynamicArguments,
2033+
});
19642034

19652035
@override
1966-
String getDisplayString({bool withNullability = false}) {
2036+
String getDisplayString({
2037+
bool withNullability = false,
2038+
bool skipAllDynamicArguments = false,
2039+
}) {
19672040
var buffer = StringBuffer();
1968-
appendTo(buffer, withNullability: withNullability);
2041+
appendTo(
2042+
buffer,
2043+
withNullability: withNullability,
2044+
skipAllDynamicArguments: skipAllDynamicArguments,
2045+
);
19692046
return buffer.toString();
19702047
}
19712048

@@ -2105,7 +2182,11 @@ class TypeParameterTypeImpl extends TypeImpl implements TypeParameterType {
21052182
}
21062183

21072184
@override
2108-
void appendTo(StringBuffer buffer, {@required bool withNullability}) {
2185+
void appendTo(
2186+
StringBuffer buffer, {
2187+
@required bool withNullability,
2188+
@required bool skipAllDynamicArguments,
2189+
}) {
21092190
buffer.write(element.name);
21102191
if (withNullability) {
21112192
_appendNullability(buffer);
@@ -2251,7 +2332,11 @@ class VoidTypeImpl extends TypeImpl implements VoidType {
22512332
bool operator ==(Object object) => identical(object, this);
22522333

22532334
@override
2254-
void appendTo(StringBuffer buffer, {@required bool withNullability}) {
2335+
void appendTo(
2336+
StringBuffer buffer, {
2337+
@required bool withNullability,
2338+
@required bool skipAllDynamicArguments,
2339+
}) {
22552340
buffer.write('void');
22562341
}
22572342

pkg/analyzer/lib/src/generated/element_resolver.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,7 @@ class ElementResolver extends SimpleAstVisitor<void> {
16831683
_resolver.errorReporter.reportErrorForNode(
16841684
StaticTypeWarningCode.UNDEFINED_SUPER_GETTER,
16851685
propertyName,
1686-
[propertyName.name, staticType.displayName],
1686+
[propertyName.name, staticType],
16871687
);
16881688
}
16891689
}
@@ -1719,7 +1719,7 @@ class ElementResolver extends SimpleAstVisitor<void> {
17191719
_resolver.errorReporter.reportErrorForNode(
17201720
StaticTypeWarningCode.UNDEFINED_SUPER_SETTER,
17211721
propertyName,
1722-
[propertyName.name, staticType.displayName],
1722+
[propertyName.name, staticType],
17231723
);
17241724
}
17251725
}

pkg/analyzer/lib/src/generated/type_system.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3798,7 +3798,11 @@ class UnknownInferredType extends TypeImpl {
37983798
bool operator ==(Object object) => identical(object, this);
37993799

38003800
@override
3801-
void appendTo(StringBuffer buffer, {bool withNullability = false}) {
3801+
void appendTo(
3802+
StringBuffer buffer, {
3803+
bool withNullability = false,
3804+
@required bool skipAllDynamicArguments,
3805+
}) {
38023806
buffer.write('?');
38033807
}
38043808

pkg/analyzer/test/generated/static_type_analyzer_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ class StaticTypeAnalyzerTest with ResourceProviderMixin, ElementsTypesMixin {
12951295

12961296
void _assertType(
12971297
InterfaceTypeImpl expectedType, InterfaceTypeImpl actualType) {
1298-
expect(actualType.displayName, expectedType.displayName);
1298+
expect(actualType.getDisplayString(), expectedType.getDisplayString());
12991299
expect(actualType.element, expectedType.element);
13001300
List<DartType> expectedArguments = expectedType.typeArguments;
13011301
int length = expectedArguments.length;

0 commit comments

Comments
 (0)