mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user