Issue-60730: Addressing the situation where we were saying that (any … (#61191)

* Issue-60730: Addressing the situation where we were saying that (any P)? does not conform to P, instead we should offer the Force Optional error messaging

* Issue-60730: Removing assigned of AllowArgumentMismatch fix that would get thrown away if we fall into ForceOptional fix

* Issue-60730: Removing file that was accidentally changed

* Issue-60730: Updating to use simplifyConformsToConstraint - and to clean up code per comments

* Issue-60730: Updating to pass protocoDecl instead of type2 to simplifyConformsToConstraint

* Issue-60730: Updating to pass protocoDecl instead of type2 to simplifyConformsToConstraint

* Issue-60730: Updating to not pass 1 to recordFix, where that is the default value

* Issue-60730: Adding in test to validate that the fix works as expected

* Issue-60730: Cleaning up test based on PR Comments

* Issue-60730: Correcting typo in test

* Issue-60730: Adding additional test cases for layers of optionals and for non-conforming argument

* Issue-60730: Updating test to include fixme(diagnostics) for multilpe layers of force unwrap
This commit is contained in:
Dylan Perry
2022-10-10 07:56:19 -04:00
committed by GitHub
parent 2c9819a415
commit a29686f349
2 changed files with 39 additions and 4 deletions

View File

@@ -3627,18 +3627,29 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
if (last.is<LocatorPathElt::ApplyArgToParam>()) {
auto proto = protoDecl->getDeclaredInterfaceType();
auto *fix = AllowArgumentMismatch::create(
*this, type1, proto, getConstraintLocator(anchor, path));
// Impact is 2 here because there are two failures
// 1 - missing conformance and 2 - incorrect argument type.
//
// This would make sure that arguments with incorrect
// conformances are not prioritized over general argument
// mismatches.
if (type1->isOptional()) {
auto unwrappedType = type1->lookThroughAllOptionalTypes();
auto result = simplifyConformsToConstraint(
unwrappedType, protoDecl, kind, locator,
subflags | TMF_ApplyingFix);
if (result == SolutionKind::Solved) {
auto fix = ForceOptional::create(*this, type1, proto,
getConstraintLocator(locator));
if (recordFix(fix))
return getTypeMatchFailure(locator);
break;
}
}
auto fix = AllowArgumentMismatch::create(
*this, type1, proto, getConstraintLocator(anchor, path));
if (recordFix(fix, /*impact=*/2))
return getTypeMatchFailure(locator);
break;
}