Skip to content

Commit 9282f1b

Browse files
committed
Fix for invalid implicit downcast in InterfaceType.allSupertypes.
[email protected] Change-Id: Ic4480fbab8ea8da6e9e8bb03ad95af66b3622618 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/155821 Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 4fcd77c commit 9282f1b

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

pkg/analyzer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Move `asInstanceOf(ClassElement)` to `DartType`, so that it is also
33
supported for `TypeParameterType` when its bound implements the
44
requested interface.
5+
* Fixed invalid implicit downcast in `InterfaceType.allSupertypes`.
56

67
## 0.39.14
78
* Removed `defaultSdkDirectory()` and `getSdkProperty()` from internal

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,9 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
719719
@override
720720
List<InterfaceType> get allSupertypes {
721721
var substitution = Substitution.fromInterfaceType(this);
722-
return element.allSupertypes.map(substitution.substituteType).toList();
722+
return element.allSupertypes
723+
.map((t) => substitution.substituteType(t) as InterfaceType)
724+
.toList();
723725
}
724726

725727
@override

pkg/analyzer/test/src/dart/element/element_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,23 @@ class FunctionTypeImplTest extends AbstractTypeTest {
12821282

12831283
@reflectiveTest
12841284
class InterfaceTypeImplTest extends AbstractTypeTest {
1285+
void test_allSupertypes() {
1286+
void check(InterfaceType type, List<String> expected) {
1287+
var actual = type.allSupertypes.map((e) {
1288+
return e.getDisplayString(
1289+
withNullability: true,
1290+
);
1291+
}).toList()
1292+
..sort();
1293+
expect(actual, expected);
1294+
}
1295+
1296+
check(objectNone, []);
1297+
check(numNone, ['Comparable<num>', 'Object']);
1298+
check(intNone, ['Comparable<num>', 'Object', 'num']);
1299+
check(listNone(intQuestion), ['Iterable<int?>', 'Object']);
1300+
}
1301+
12851302
test_asInstanceOf_explicitGeneric() {
12861303
// class A<E> {}
12871304
// class B implements A<C> {}

0 commit comments

Comments
 (0)