Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 442836b

Browse files
chloestefantsovaCommit Bot
authored andcommitted
[cfe] Fail early on some subtype checks instead of crashing
Some subtype tests are crashing due to infinite recursion. It is a known issue. An example of such test is FutureOr<T> against FutureOr<S> where T and S are type variables declared as T extends FutureOr<T> and S extends FutureOr<S>. In some cases it's possible to fail early instead of crashing, for exmaple, by checking Future-branch of the left-hand side first before checking the type argumennt of FutureOr which would lead to the infinite recursion. This CL does that, allowing some more type checks to pass instead of crashing. Change-Id: I075aa65522510db1a97ac2a8de7278a3ce3f400c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/227820 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Chloe Stefantsova <[email protected]>
1 parent f74c08a commit 442836b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

pkg/front_end/test/fasta/types/shared_type_tests.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,10 @@ abstract class SubtypeTest<T, E> {
426426
typeParameters: 'T extends Object');
427427
isObliviousSubtype('T & Future<int?>', 'FutureOr<num>?',
428428
typeParameters: 'T extends Object');
429+
isNotSubtype('FutureOr<T?>?', 'FutureOr<Never?>?',
430+
typeParameters: 'T extends FutureOr<T?>?');
431+
isSubtype('FutureOr<Never?>?', 'FutureOr<T?>?',
432+
typeParameters: 'T extends FutureOr<T?>?');
429433

430434
if (!skipFutureOrPromotion) {
431435
isSubtype('T & FutureOr<int*>*', 'FutureOr<num*>*', typeParameters: 'T');

pkg/kernel/lib/src/types.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,11 @@ class IsInterfaceSubtypeOf extends TypeRelation<InterfaceType> {
404404
IsSubtypeOf isFutureOrRelated(FutureOrType s, InterfaceType t, Types types) {
405405
// Rules 7.1 and 7.2.
406406
return types
407-
.performNullabilityAwareSubtypeCheck(s.typeArgument, t)
408-
.andSubtypeCheckFor(
407+
.performNullabilityAwareSubtypeCheck(
409408
new InterfaceType(types.hierarchy.coreTypes.futureClass,
410409
Nullability.nonNullable, [s.typeArgument]),
411-
t,
412-
types)
410+
t)
411+
.andSubtypeCheckFor(s.typeArgument, t, types)
413412
.and(new IsSubtypeOf.basedSolelyOnNullabilities(s, t));
414413
}
415414

0 commit comments

Comments
 (0)