Merge pull request #26541 from hborla/autoclosure-optional-ptr-conversion-diag

[Diagnostics] Improve the diagnostic for invalid optional pointer conversions for an autoclosure result type.
This commit is contained in:
Holly Borla
2019-08-20 10:58:33 -07:00
committed by GitHub
4 changed files with 39 additions and 35 deletions

View File

@@ -2618,6 +2618,14 @@ bool ConstraintSystem::repairFailures(
case ConstraintLocator::AutoclosureResult: {
if (repairByInsertingExplicitCall(lhs, rhs))
return true;
auto result = matchTypes(lhs, rhs, ConstraintKind::ArgumentConversion,
TypeMatchFlags::TMF_ApplyingFix,
locator.withPathElement(ConstraintLocator::FunctionArgument));
if (result.isSuccess())
conversionsOrFixes.push_back(AllowAutoClosurePointerConversion::create(
*this, lhs, rhs, getConstraintLocator(locator)));
break;
}
@@ -3224,10 +3232,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
if (kind >= ConstraintKind::Conversion) {
// It is never legal to form an autoclosure that results in these
// implicit conversions to pointer types.
bool isAutoClosureArgument = false;
if (auto last = locator.last())
if (last->getKind() == ConstraintLocator::AutoclosureResult)
isAutoClosureArgument = true;
bool isAutoClosureArgument = locator.isForAutoclosureResult();
// Pointer arguments can be converted from pointer-compatible types.
if (kind >= ConstraintKind::ArgumentConversion) {
@@ -3263,11 +3268,6 @@ 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);
}
}
@@ -7200,13 +7200,6 @@ 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: