Skip to content

Commit a73c8d0

Browse files
committed
MethodElementImpl.getReifiedType() should always create new parameter elements.
If we don't, and we transplant any of them into a new detached instance of synthetic FunctionElementImpl, they are not able to access later enclosingUnit in order to resynthesize their type. [email protected] BUG= Review-Url: https://codereview.chromium.org/2829843002 .
1 parent 8a64625 commit a73c8d0

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6661,23 +6661,22 @@ class MethodElementImpl extends ExecutableElementImpl implements MethodElement {
66616661

66626662
@override
66636663
FunctionType getReifiedType(DartType objectType) {
6664-
// Collect the covariant parameters. Do this first so we don't allocate
6665-
// anything in the common case where there are none.
6666-
Set<String> covariantNames;
6664+
// Check whether we have any covariant parameters.
6665+
// Usually we don't, so we can use the same type.
6666+
bool hasCovariant = false;
66676667
for (ParameterElement parameter in parameters) {
66686668
if (parameter.isCovariant) {
6669-
covariantNames ??= new Set();
6670-
covariantNames.add(parameter.name);
6669+
hasCovariant = true;
6670+
break;
66716671
}
66726672
}
66736673

6674-
if (covariantNames == null) return type;
6674+
if (!hasCovariant) {
6675+
return type;
6676+
}
66756677

66766678
List<ParameterElement> covariantParameters = parameters.map((parameter) {
6677-
if (!covariantNames.contains(parameter.name)) {
6678-
return parameter;
6679-
}
6680-
6679+
DartType type = parameter.isCovariant ? objectType : parameter.type;
66816680
return new ParameterElementImpl.synthetic(
66826681
parameter.name, objectType, parameter.parameterKind);
66836682
}).toList();

0 commit comments

Comments
 (0)