@@ -2178,14 +2178,10 @@ namespace {
2178
2178
};
2179
2179
} // end anonymous namespace
2180
2180
2181
- static bool matches (CanType t1, CanType t2, TypeMatchOptions matchMode,
2182
- ParameterPosition paramPosition,
2183
- OptionalUnwrapping insideOptional);
2184
-
2185
2181
static bool matchFunctionTypes (CanAnyFunctionType fn1, CanAnyFunctionType fn2,
2186
2182
TypeMatchOptions matchMode,
2187
- ParameterPosition paramPosition ,
2188
- OptionalUnwrapping insideOptional ) {
2183
+ OptionalUnwrapping insideOptional ,
2184
+ std::function< bool ()> paramsAndResultMatch ) {
2189
2185
// FIXME: Handle generic functions in non-ABI matches.
2190
2186
if (!matchMode.contains (TypeMatchFlags::AllowABICompatible)) {
2191
2187
if (!isa<FunctionType>(fn1) || !isa<FunctionType>(fn2))
@@ -2214,11 +2210,7 @@ static bool matchFunctionTypes(CanAnyFunctionType fn1, CanAnyFunctionType fn2,
2214
2210
if (ext1 != ext2)
2215
2211
return false ;
2216
2212
2217
- // Inputs are contravariant, results are covariant.
2218
- return (matches (fn2.getInput (), fn1.getInput (), matchMode,
2219
- ParameterPosition::Parameter, OptionalUnwrapping::None) &&
2220
- matches (fn1.getResult (), fn2.getResult (), matchMode,
2221
- ParameterPosition::NotParameter, OptionalUnwrapping::None));
2213
+ return paramsAndResultMatch ();
2222
2214
}
2223
2215
2224
2216
static bool matches (CanType t1, CanType t2, TypeMatchOptions matchMode,
@@ -2298,8 +2290,17 @@ static bool matches(CanType t1, CanType t2, TypeMatchOptions matchMode,
2298
2290
if (!fn1)
2299
2291
return false ;
2300
2292
2301
- return matchFunctionTypes (fn1, fn2, matchMode, paramPosition,
2302
- insideOptional);
2293
+ std::function<bool ()> paramsAndResultMatch = [=]() {
2294
+ // Inputs are contravariant, results are covariant.
2295
+ return (matches (fn2.getInput (), fn1.getInput (), matchMode,
2296
+ ParameterPosition::Parameter, OptionalUnwrapping::None) &&
2297
+ matches (fn1.getResult (), fn2.getResult (), matchMode,
2298
+ ParameterPosition::NotParameter,
2299
+ OptionalUnwrapping::None));
2300
+ };
2301
+
2302
+ return matchFunctionTypes (fn1, fn2, matchMode, insideOptional,
2303
+ paramsAndResultMatch);
2303
2304
}
2304
2305
2305
2306
if (matchMode.contains (TypeMatchFlags::AllowNonOptionalForIUOParam) &&
0 commit comments