Skip to content

Commit a2d1ef6

Browse files
committed
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
1 parent edd8d1c commit a2d1ef6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

include/swift/Option/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,9 @@ def tools_directory : Separate<["-"], "tools-directory">,
241241

242242
def D : JoinedOrSeparate<["-"], "D">, Flags<[FrontendOption]>,
243243
HelpText<"Marks a conditional compilation flag as true">;
244+
245+
def e : JoinedOrSeparate<["-"], "e">, Flags<[NewDriverOnlyOption]>,
246+
HelpText<"Executes a line of code provided on the command line">;
244247

245248
def F : JoinedOrSeparate<["-"], "F">,
246249
Flags<[FrontendOption, ArgumentIsPath, SwiftAPIExtractOption, SwiftSymbolGraphExtractOption, SwiftAPIDigesterOption]>,

lib/Sema/CSSimplify.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3635,9 +3635,22 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
36353635
// This would make sure that arguments with incorrect
36363636
// conformances are not prioritized over general argument
36373637
// mismatches.
3638-
if (recordFix(fix, /*impact=*/2))
3638+
auto impact = 2;
3639+
if (type1->isOptional()) {
3640+
auto unwrappedType = type1->getOptionalObjectType();
3641+
auto matchTypeResult =
3642+
matchTypes(unwrappedType, type2, ConstraintKind::Conversion,
3643+
subflags, locator);
3644+
if (matchTypeResult.isSuccess()) {
3645+
// Impact here is a 1 because there is only one failure before
3646+
// we need to force type1 to be
3647+
impact = 1;
3648+
fix = ForceOptional::create(*this, type1, proto,
3649+
getConstraintLocator(locator));
3650+
}
3651+
}
3652+
if (recordFix(fix, /*impact=*/impact))
36393653
return getTypeMatchFailure(locator);
3640-
36413654
break;
36423655
}
36433656

0 commit comments

Comments
 (0)