mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge pull request #26470 from hborla/autoclosure-pointer-conversion-diagnostic
[Diagnostics] Improve the diagnostic for invalid pointer conversion for an autoclosure result type.
This commit is contained in:
@@ -3087,8 +3087,8 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
|
||||
case PTK_UnsafeMutablePointer:
|
||||
// UnsafeMutablePointer can be converted from an inout reference to a
|
||||
// scalar or array.
|
||||
if (!isAutoClosureArgument) {
|
||||
if (auto inoutType1 = dyn_cast<InOutType>(desugar1)) {
|
||||
if (auto inoutType1 = dyn_cast<InOutType>(desugar1)) {
|
||||
if (!isAutoClosureArgument) {
|
||||
auto inoutBaseType = inoutType1->getInOutObjectType();
|
||||
|
||||
Type simplifiedInoutBaseType = getFixedTypeRecursive(
|
||||
@@ -3103,6 +3103,11 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
|
||||
}
|
||||
conversionsOrFixes.push_back(
|
||||
ConversionRestrictionKind::InoutToPointer);
|
||||
} else {
|
||||
Type pointeeType = inoutType1->getObjectType();
|
||||
auto *fix = AllowAutoClosurePointerConversion::create(*this,
|
||||
pointeeType, type2, getConstraintLocator(locator));
|
||||
conversionsOrFixes.push_back(fix);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6998,6 +7003,13 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
|
||||
return matchTupleTypes(matchingType, smaller, matchKind, subflags, locator);
|
||||
}
|
||||
|
||||
case FixKind::AllowAutoClosurePointerConversion: {
|
||||
if (recordFix(fix))
|
||||
return SolutionKind::Error;
|
||||
return matchTypes(type1, type2, matchKind, subflags,
|
||||
locator.withPathElement(ConstraintLocator::FunctionArgument));
|
||||
}
|
||||
|
||||
case FixKind::InsertCall:
|
||||
case FixKind::RemoveReturn:
|
||||
case FixKind::AddConformance:
|
||||
|
||||
Reference in New Issue
Block a user