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:
Holly Borla
2019-08-05 10:06:15 -07:00
committed by GitHub
7 changed files with 89 additions and 10 deletions

View File

@@ -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: