@@ -898,23 +898,18 @@ abstract class TypeConstraintGenerator<
898898 List <TypeStructure >? getTypeArgumentsAsInstanceOf (
899899 TypeDeclarationType type, TypeDeclaration typeDeclaration);
900900
901- /// Matches [p] against [q] as a subtype against supertype and returns true if
902- /// [p] and [q] are both function types, and [p] is a subtype of [q] under
903- /// some constraints imposed on type parameters occurring in [q] ; false if
904- /// both [p] and [q] are function types, but [p] can't possibly be a subtype
905- /// of [q] under any constraints; and null otherwise.
901+ /// Matches [p] against [q] .
902+ ///
903+ /// If [p] and [q] are both non-generic function types, and [p] is a subtype
904+ /// of [q] under some constraints, the constraints making the relation
905+ /// possible are recorded, and `true` is returned. Otherwise, the constraint
906+ /// state is unchanged (or rolled back using [restoreState] ), and `null` is
907+ /// returned.
906908 ///
907909 /// An invariant of the type inference is that only [p] or [q] may be a
908910 /// schema (in other words, may contain the unknown type `_` ); the other must
909911 /// be simply a type. If [leftSchema] is `true` , [p] may contain `_` ; if it is
910912 /// `false` , [q] may contain `_` .
911- ///
912- /// As the generator computes the constraints making the relation possible, it
913- /// changes its internal state. The current state of the generator can be
914- /// obtained by [currentState] , and the generator can be restored to a state
915- /// via [restoreState] . All of the shared constraint generation methods are
916- /// supposed to restore the generator to the prior state in case of a
917- /// mismatch, taking that responsibility away from the caller.
918913 bool ? performSubtypeConstraintGenerationForFunctionTypes (
919914 TypeStructure p, TypeStructure q,
920915 {required bool leftSchema, required AstNode ? astNodeForTesting}) {
@@ -943,7 +938,6 @@ abstract class TypeConstraintGenerator<
943938 if (! performSubtypeConstraintGenerationInternal (
944939 p.returnType, q.returnType,
945940 leftSchema: leftSchema, astNodeForTesting: astNodeForTesting)) {
946- restoreState (state);
947941 return null ;
948942 }
949943 for (int i = 0 ; i < q.positionalParameterTypes.length; ++ i) {
@@ -973,7 +967,6 @@ abstract class TypeConstraintGenerator<
973967 if (! performSubtypeConstraintGenerationInternal (
974968 p.returnType, q.returnType,
975969 leftSchema: leftSchema, astNodeForTesting: astNodeForTesting)) {
976- restoreState (state);
977970 return null ;
978971 }
979972 for (int i = 0 ; i < p.positionalParameterTypes.length; ++ i) {
@@ -1048,23 +1041,18 @@ abstract class TypeConstraintGenerator<
10481041 return null ;
10491042 }
10501043
1051- /// Matches [p] against [q] as a subtype against supertype and returns true if
1052- /// [p] and [q] are both FutureOr, with or without nullability suffixes as
1053- /// defined by [enableDiscrepantObliviousnessOfNullabilitySuffixOfFutureOr] ,
1054- /// and [p] is a subtype of [q] under some constraints imposed on type
1055- /// parameters occurring in [q] , and false otherwise.
1044+ /// Matches [p] against [q] .
1045+ ///
1046+ /// If [q] is of the form `FutureOr<q0>` for some `q0` , and [p] is a subtype
1047+ /// of [q] under some constraints, the constraints making the relation
1048+ /// possible are recorded, and `true` is returned. Otherwise, the constraint
1049+ /// state is unchanged (or rolled back using [restoreState] ), and `false` is
1050+ /// returned.
10561051 ///
10571052 /// An invariant of the type inference is that only [p] or [q] may be a
10581053 /// schema (in other words, may contain the unknown type `_` ); the other must
10591054 /// be simply a type. If [leftSchema] is `true` , [p] may contain `_` ; if it is
10601055 /// `false` , [q] may contain `_` .
1061- ///
1062- /// As the generator computes the constraints making the relation possible,
1063- /// it changes its internal state. The current state of the generator can be
1064- /// obtained by [currentState] , and the generator can be restored to a state
1065- /// via [restoreState] . All of the shared constraint generation methods are
1066- /// supposed to restore the generator to the prior state in case of a
1067- /// mismatch, taking that responsibility away from the caller.
10681056 bool performSubtypeConstraintGenerationForFutureOr (
10691057 TypeStructure p, TypeStructure q,
10701058 {required bool leftSchema, required AstNode ? astNodeForTesting}) {
@@ -1083,7 +1071,6 @@ abstract class TypeConstraintGenerator<
10831071 leftSchema: leftSchema, astNodeForTesting: astNodeForTesting)) {
10841072 return true ;
10851073 }
1086- restoreState (state);
10871074 }
10881075
10891076 // Or if `P` is a subtype match for `Future<Q0>` under non-empty
@@ -1095,14 +1082,12 @@ abstract class TypeConstraintGenerator<
10951082 if (isMatchWithFuture && matchWithFutureAddsConstraints) {
10961083 return true ;
10971084 }
1098- restoreState (state);
10991085
11001086 // Or if `P` is a subtype match for `Q0` under constraint set `C`.
11011087 if (performSubtypeConstraintGenerationInternal (p, q0,
11021088 leftSchema: leftSchema, astNodeForTesting: astNodeForTesting)) {
11031089 return true ;
11041090 }
1105- restoreState (state);
11061091
11071092 // Or if `P` is a subtype match for `Future<Q0>` under empty
11081093 // constraint set `C`.
@@ -1114,24 +1099,22 @@ abstract class TypeConstraintGenerator<
11141099 return false ;
11151100 }
11161101
1117- /// Matches [p] against [q] as a subtype against supertype and returns true if
1118- /// [p] and [q] are both type declaration types as defined by the enum
1119- /// [TypeDeclarationKind] , and [p] is a subtype of [q] under some constraints
1120- /// imposed on type parameters occurring in [q] ; false if both [p] and [q] are
1121- /// type declaration types, but [p] can't possibly be a subtype of [q] under
1122- /// any constraints; and null otherwise.
1102+ /// Matches [p] against [q] as a subtype against supertype.
1103+ ///
1104+ /// If [p] and [q] are both type declaration types, then:
1105+ ///
1106+ /// - If [p] is a subtype of [q] under some constraints, the constraints
1107+ /// making the relation possible are recorded, and `true` is returned.
1108+ /// - Otherwise, the constraint state is unchanged (or rolled back using
1109+ /// [restoreState] ), and `false` is returned.
1110+ ///
1111+ /// Otherwise (either [p] or [q] is not a type declaration type), the
1112+ /// constraint state is unchanged, and `null` is returned.
11231113 ///
11241114 /// An invariant of the type inference is that only [p] or [q] may be a
11251115 /// schema (in other words, may contain the unknown type `_` ); the other must
11261116 /// be simply a type. If [leftSchema] is `true` , [p] may contain `_` ; if it is
11271117 /// `false` , [q] may contain `_` .
1128- ///
1129- /// As the generator computes the constraints making the relation possible, it
1130- /// changes its internal state. The current state of the generator can be
1131- /// obtained by [currentState] , and the generator can be restored to a state
1132- /// via [restoreState] . All of the shared constraint generation methods are
1133- /// supposed to restore the generator to the prior state in case of a
1134- /// mismatch, taking that responsibility away from the caller.
11351118 bool ? performSubtypeConstraintGenerationForTypeDeclarationTypes (
11361119 TypeStructure p, TypeStructure q,
11371120 {required bool leftSchema, required AstNode ? astNodeForTesting}) {
@@ -1174,6 +1157,14 @@ abstract class TypeConstraintGenerator<
11741157 }
11751158 }
11761159
1160+ /// Implementation backing [performSubtypeConstraintGenerationLeftSchema] and
1161+ /// [performSubtypeConstraintGenerationRightSchema] .
1162+ ///
1163+ /// If [p] is a subtype of [q] under some constraints, the constraints making
1164+ /// the relation possible are recorded, and `true` is returned. Otherwise,
1165+ /// the constraint state is unchanged (or rolled back using [restoreState] ),
1166+ /// and `false` is returned.
1167+ ///
11771168 /// [performSubtypeConstraintGenerationInternal] should be implemented by
11781169 /// concrete classes implementing [TypeConstraintGenerator] . The
11791170 /// implementations of [performSubtypeConstraintGenerationLeftSchema] and
@@ -1201,9 +1192,8 @@ abstract class TypeConstraintGenerator<
12011192 /// As the generator computes the constraints making the relation possible,
12021193 /// it changes its internal state. The current state of the generator can be
12031194 /// obtained by [currentState] , and the generator can be restored to a state
1204- /// via [restoreState] . All of the shared constraint generation methods are
1205- /// supposed to restore the generator to the prior state in case of a
1206- /// mismatch, taking that responsibility away from the caller.
1195+ /// via [restoreState] . If this method returns `false` , it restores the state,
1196+ /// so it is not necessary for the caller to do so.
12071197 ///
12081198 /// The algorithm for subtype constraint generation is described in
12091199 /// https://github.com/dart-lang/language/blob/main/resources/type-system/inference.md#subtype-constraint-generation
@@ -1219,9 +1209,8 @@ abstract class TypeConstraintGenerator<
12191209 /// As the generator computes the constraints making the relation possible,
12201210 /// it changes its internal state. The current state of the generator can be
12211211 /// obtained by [currentState] , and the generator can be restored to a state
1222- /// via [restoreState] . All of the shared constraint generation methods are
1223- /// supposed to restore the generator to the prior state in case of a
1224- /// mismatch, taking that responsibility away from the caller.
1212+ /// via [restoreState] . If this method returns `false` , it restores the state,
1213+ /// so it is not necessary for the caller to do so.
12251214 ///
12261215 /// The algorithm for subtype constraint generation is described in
12271216 /// https://github.com/dart-lang/language/blob/main/resources/type-system/inference.md#subtype-constraint-generation
@@ -1271,6 +1260,13 @@ abstract class TypeConstraintGenerator<
12711260 return true ;
12721261 }
12731262
1263+ /// Matches [p] against [q] , assuming both [p] and [q] are both type
1264+ /// declaration types that refer to different type declarations.
1265+ ///
1266+ /// If [p] is a subtype of [q] under some constraints, the constraints making
1267+ /// the relation possible are recorded, and `true` is returned. Otherwise,
1268+ /// the constraint state is unchanged (or rolled back using [restoreState] ),
1269+ /// and `false` is returned.
12741270 bool _interfaceTypes (TypeStructure p, TypeStructure q, bool leftSchema,
12751271 {required AstNode ? astNodeForTesting}) {
12761272 if (p.nullabilitySuffix != NullabilitySuffix .none) {
0 commit comments