Skip to content

Commit a86d55e

Browse files
scheglovwhesse
authored andcommitted
Instantiate parameterized types of type parameters with 'dynamic' type arguments.
There is internal code like the added test, which caused us to use out of scope type parameter during inferred type computation. Possibly related issues. #26990 #27072 [email protected], [email protected], [email protected] BUG= Review URL: https://codereview.chromium.org/2376213003 .
1 parent 4e6ff19 commit a86d55e

File tree

4 files changed

+23
-34
lines changed

4 files changed

+23
-34
lines changed

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8129,21 +8129,6 @@ abstract class TypeParameterizedElementMixin
81298129
*/
81308130
List<UnlinkedTypeParam> get unlinkedTypeParams;
81318131

8132-
/**
8133-
* Determine the default value of type argument [i]. in most cases this will
8134-
* be `dynamic`, but sometimes it will be the bound of the ith type parameter.
8135-
*/
8136-
DartType computeDefaultTypeArgument(int i) {
8137-
// If strong mode is off, or we can tell quickly from the summary that there
8138-
// is no bound, then the default type argument is `dynamic`; we don't have
8139-
// to call `typeParameters` to find that out.
8140-
if (!context.analysisOptions.strongMode ||
8141-
(unlinkedTypeParams != null && unlinkedTypeParams[i].bound == null)) {
8142-
return DynamicTypeImpl.instance;
8143-
}
8144-
return typeParameters[i].bound ?? DynamicTypeImpl.instance;
8145-
}
8146-
81478132
/**
81488133
* Convert the given [index] into a type parameter type.
81498134
*/

pkg/analyzer/lib/src/summary/link.dart

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -606,14 +606,14 @@ class ClassElementForLink_Class extends ClassElementForLink
606606
DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) {
607607
int numTypeParameters = _unlinkedClass.typeParameters.length;
608608
if (numTypeParameters != 0) {
609-
return new InterfaceTypeImpl.elementWithNameAndArgs(this, name, () {
610-
List<DartType> typeArguments = new List<DartType>(numTypeParameters);
611-
for (int i = 0; i < numTypeParameters; i++) {
612-
typeArguments[i] =
613-
getTypeArgument(i) ?? computeDefaultTypeArgument(i);
614-
}
615-
return typeArguments;
616-
});
609+
List<DartType> typeArguments =
610+
new List<DartType>.generate(numTypeParameters, getTypeArgument);
611+
if (typeArguments.contains(null)) {
612+
return context.typeSystem.instantiateToBounds(this.type);
613+
} else {
614+
return new InterfaceTypeImpl.elementWithNameAndArgs(
615+
this, name, () => typeArguments);
616+
}
617617
} else {
618618
return _type ??= new InterfaceTypeImpl(this);
619619
}
@@ -3177,12 +3177,15 @@ class FunctionTypeAliasElementForLink extends Object
31773177
DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) {
31783178
int numTypeParameters = _unlinkedTypedef.typeParameters.length;
31793179
if (numTypeParameters != 0) {
3180-
List<DartType> typeArguments = new List<DartType>(numTypeParameters);
3181-
for (int i = 0; i < numTypeParameters; i++) {
3182-
typeArguments[i] = getTypeArgument(i) ?? computeDefaultTypeArgument(i);
3180+
List<DartType> typeArguments =
3181+
new List<DartType>.generate(numTypeParameters, getTypeArgument);
3182+
if (typeArguments.contains(null)) {
3183+
return context.typeSystem
3184+
.instantiateToBounds(new FunctionTypeImpl.forTypedef(this));
3185+
} else {
3186+
return new FunctionTypeImpl.elementWithNameAndArgs(
3187+
this, name, typeArguments, true);
31833188
}
3184-
return new FunctionTypeImpl.elementWithNameAndArgs(
3185-
this, name, typeArguments, true);
31863189
} else {
31873190
return _type ??= new FunctionTypeImpl.forTypedef(this);
31883191
}
@@ -4407,6 +4410,9 @@ abstract class ReferenceableElementForLink implements Element {
44074410
*/
44084411
TypeInferenceNode get asTypeInferenceNode => null;
44094412

4413+
@override
4414+
ElementLocation get location => new ElementLocationImpl.con1(this);
4415+
44104416
/**
44114417
* Return the type indicated by this element when it is used in a
44124418
* type instantiation context. If this element can't legally be

pkg/analyzer/test/src/summary/resynthesize_ast_test.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,6 @@ class AstInferredTypeTest extends AbstractResynthesizeTest
152152
super.test_circularReference_viaClosures_initializerTypes();
153153
}
154154

155-
@override
156-
@failingTest
157-
void test_constructors_inferenceFBounded() {
158-
super.test_constructors_inferenceFBounded();
159-
}
160-
161155
@override
162156
@failingTest
163157
void test_constructors_inferFromArguments() {

pkg/analyzer/test/src/summary/resynthesize_common.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3578,6 +3578,10 @@ C c;
35783578
checkLibrary('''
35793579
class C<T extends C<T>> {}
35803580
C c;
3581+
var c2 = new C();
3582+
class B {
3583+
var c3 = new C();
3584+
}
35813585
''');
35823586
}
35833587

0 commit comments

Comments
 (0)