@@ -2161,10 +2161,18 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
21612161 // an implicit closure.
21622162 if (auto function2 = type2->getAs <FunctionType>()) {
21632163 if (function2->isAutoClosure ())
2164- return matchTypes (type1, function2->getResult (), kind, subflags,
2165- locator.withPathElement (ConstraintLocator::Load));
2164+ return matchTypes (
2165+ type1, function2->getResult (), kind, subflags,
2166+ locator.withPathElement (ConstraintLocator::AutoclosureResult));
21662167 }
21672168
2169+ // It is never legal to form an autoclosure that results in these
2170+ // implicit conversions to pointer types.
2171+ bool isAutoClosureArgument = false ;
2172+ if (auto last = locator.last ())
2173+ if (last->getKind () == ConstraintLocator::AutoclosureResult)
2174+ isAutoClosureArgument = true ;
2175+
21682176 // Pointer arguments can be converted from pointer-compatible types.
21692177 if (kind >= ConstraintKind::ArgumentConversion) {
21702178 Type unwrappedType2 = type2;
@@ -2183,23 +2191,24 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
21832191 case PTK_UnsafeMutablePointer:
21842192 // UnsafeMutablePointer can be converted from an inout reference to a
21852193 // scalar or array.
2186- if (auto inoutType1 = dyn_cast<InOutType>(desugar1)) {
2187- auto inoutBaseType = inoutType1->getInOutObjectType ();
2188-
2189- Type simplifiedInoutBaseType =
2190- getFixedTypeRecursive (inoutBaseType,
2191- kind == ConstraintKind::Equal,
2192- isArgumentTupleConversion);
2193-
2194- // FIXME: If the base is still a type variable, we can't tell
2195- // what to do here. Might have to try \c ArrayToPointer and make it
2196- // more robust.
2197- if (isArrayType (simplifiedInoutBaseType)) {
2194+ if (!isAutoClosureArgument) {
2195+ if (auto inoutType1 = dyn_cast<InOutType>(desugar1)) {
2196+ auto inoutBaseType = inoutType1->getInOutObjectType ();
2197+
2198+ Type simplifiedInoutBaseType = getFixedTypeRecursive (
2199+ inoutBaseType, kind == ConstraintKind::Equal,
2200+ isArgumentTupleConversion);
2201+
2202+ // FIXME: If the base is still a type variable, we can't tell
2203+ // what to do here. Might have to try \c ArrayToPointer and make
2204+ // it more robust.
2205+ if (isArrayType (simplifiedInoutBaseType)) {
2206+ conversionsOrFixes.push_back (
2207+ ConversionRestrictionKind::ArrayToPointer);
2208+ }
21982209 conversionsOrFixes.push_back (
2199- ConversionRestrictionKind::ArrayToPointer );
2210+ ConversionRestrictionKind::InoutToPointer );
22002211 }
2201- conversionsOrFixes.push_back (
2202- ConversionRestrictionKind::InoutToPointer);
22032212 }
22042213
22052214 if (!flags.contains (TMF_ApplyingOperatorParameter) &&
@@ -2247,20 +2256,22 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
22472256 // AutoreleasingUnsafeMutablePointer.
22482257 if (pointerKind == PTK_UnsafePointer
22492258 || pointerKind == PTK_UnsafeRawPointer) {
2250- if (isArrayType (type1)) {
2251- conversionsOrFixes.push_back (
2252- ConversionRestrictionKind::ArrayToPointer);
2253- }
2254-
2255- // The pointer can be converted from a string, if the element type
2256- // is compatible.
2257- if (type1->isEqual (TC.getStringType (DC))) {
2258- auto baseTy = getFixedTypeRecursive (pointeeTy, false );
2259-
2260- if (baseTy->isTypeVariableOrMember () ||
2261- isStringCompatiblePointerBaseType (TC, DC, baseTy))
2259+ if (!isAutoClosureArgument) {
2260+ if (isArrayType (type1)) {
22622261 conversionsOrFixes.push_back (
2263- ConversionRestrictionKind::StringToPointer);
2262+ ConversionRestrictionKind::ArrayToPointer);
2263+ }
2264+
2265+ // The pointer can be converted from a string, if the element
2266+ // type is compatible.
2267+ if (type1->isEqual (TC.getStringType (DC))) {
2268+ auto baseTy = getFixedTypeRecursive (pointeeTy, false );
2269+
2270+ if (baseTy->isTypeVariableOrMember () ||
2271+ isStringCompatiblePointerBaseType (TC, DC, baseTy))
2272+ conversionsOrFixes.push_back (
2273+ ConversionRestrictionKind::StringToPointer);
2274+ }
22642275 }
22652276
22662277 if (type1IsPointer && optionalityMatches &&
@@ -2276,7 +2287,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
22762287 case PTK_AutoreleasingUnsafeMutablePointer:
22772288 // PTK_AutoreleasingUnsafeMutablePointer can be converted from an
22782289 // inout reference to a scalar.
2279- if (type1->is <InOutType>()) {
2290+ if (!isAutoClosureArgument && type1->is <InOutType>()) {
22802291 conversionsOrFixes.push_back (
22812292 ConversionRestrictionKind::InoutToPointer);
22822293 }
0 commit comments