@@ -2232,7 +2232,7 @@ bool TypeBase::isTriviallyRepresentableIn(ForeignLanguage language,
2232
2232
// / Is t1 not just a subtype of t2, but one such that its values are
2233
2233
// / trivially convertible to values of the other?
2234
2234
static bool canOverride (CanType t1, CanType t2,
2235
- bool allowUnsafeParameterOverride ,
2235
+ OverrideMatchMode matchMode ,
2236
2236
bool isParameter,
2237
2237
bool insideOptional,
2238
2238
LazyResolver *resolver) {
@@ -2246,7 +2246,7 @@ static bool canOverride(CanType t1, CanType t2,
2246
2246
if (!tuple1 || tuple1->getNumElements () != tuple2->getNumElements ()) {
2247
2247
if (tuple2->getNumElements () == 1 )
2248
2248
return canOverride (t1, tuple2.getElementType (0 ),
2249
- allowUnsafeParameterOverride ,
2249
+ matchMode ,
2250
2250
isParameter,
2251
2251
/* insideOptional=*/ false ,
2252
2252
resolver);
@@ -2256,7 +2256,7 @@ static bool canOverride(CanType t1, CanType t2,
2256
2256
for (auto i : indices (tuple1.getElementTypes ())) {
2257
2257
if (!canOverride (tuple1.getElementType (i),
2258
2258
tuple2.getElementType (i),
2259
- allowUnsafeParameterOverride ,
2259
+ matchMode ,
2260
2260
isParameter,
2261
2261
/* insideOptional=*/ false ,
2262
2262
resolver))
@@ -2283,12 +2283,12 @@ static bool canOverride(CanType t1, CanType t2,
2283
2283
2284
2284
// Inputs are contravariant, results are covariant.
2285
2285
return (canOverride (fn2.getInput (), fn1.getInput (),
2286
- allowUnsafeParameterOverride ,
2286
+ matchMode ,
2287
2287
/* isParameter=*/ true ,
2288
2288
/* insideOptional=*/ false ,
2289
2289
resolver) &&
2290
2290
canOverride (fn1.getResult (), fn2.getResult (),
2291
- allowUnsafeParameterOverride ,
2291
+ matchMode ,
2292
2292
/* isParameter=*/ false ,
2293
2293
/* insideOptional=*/ false ,
2294
2294
resolver));
@@ -2301,22 +2301,23 @@ static bool canOverride(CanType t1, CanType t2,
2301
2301
// Optional-to-optional.
2302
2302
if (auto obj1 = t1.getAnyOptionalObjectType ()) {
2303
2303
// Allow T? and T! to freely override one another.
2304
- return canOverride (obj1, obj2, allowUnsafeParameterOverride ,
2304
+ return canOverride (obj1, obj2, matchMode ,
2305
2305
/* isParameter=*/ false ,
2306
2306
/* insideOptional=*/ true ,
2307
2307
resolver);
2308
2308
}
2309
2309
2310
2310
// Value-to-optional.
2311
- return canOverride (t1, obj2, allowUnsafeParameterOverride ,
2311
+ return canOverride (t1, obj2, matchMode ,
2312
2312
/* isParameter=*/ false ,
2313
2313
/* insideOptional=*/ true ,
2314
2314
resolver);
2315
2315
}
2316
2316
}
2317
2317
2318
2318
// Allow T to override T! in certain cases.
2319
- if (allowUnsafeParameterOverride && isParameter && !insideOptional) {
2319
+ if (matchMode == OverrideMatchMode::AllowNonOptionalForIUOParam &&
2320
+ isParameter && !insideOptional) {
2320
2321
if (auto obj1 = t1->getImplicitlyUnwrappedOptionalObjectType ()) {
2321
2322
t1 = obj1->getCanonicalType ();
2322
2323
if (t1 == t2) return true ;
@@ -2327,10 +2328,10 @@ static bool canOverride(CanType t1, CanType t2,
2327
2328
return t2->isExactSuperclassOf (t1, resolver);
2328
2329
}
2329
2330
2330
- bool TypeBase::canOverride (Type other, bool allowUnsafeParameterOverride ,
2331
+ bool TypeBase::canOverride (Type other, OverrideMatchMode matchMode ,
2331
2332
LazyResolver *resolver) {
2332
2333
return ::canOverride (getCanonicalType (), other->getCanonicalType (),
2333
- allowUnsafeParameterOverride ,
2334
+ matchMode ,
2334
2335
/* isParameter=*/ false ,
2335
2336
/* insideOptional=*/ false ,
2336
2337
resolver);
0 commit comments