Skip to content

Commit f67687b

Browse files
committed
[CSSimplify] Fix matchDeepEqualityTypes to allow fixing of optionals
Attempting to propagate generic argument failures up is not always reliable, `matchDeepEqualityTypes` should avoid using `TMF_ApplyingFix` while dealing with optionals and instead let `repairFailures` decide whether to use generic arguments mismatch fix to a more general one. (cherry picked from commit 27c28d4)
1 parent 143931a commit f67687b

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4039,6 +4039,12 @@ ConstraintSystem::matchDeepEqualityTypes(Type type1, Type type2,
40394039
getConstraintLocator(locator, {LocatorPathElt::GenericType(type1),
40404040
LocatorPathElt::GenericType(type2)});
40414041

4042+
// Optionals have a lot of special diagnostics and only one
4043+
// generic argument so if we're dealing with one, let's allow
4044+
// `repairFailures` to take care of it.
4045+
if (bound1->getDecl()->isOptionalDecl())
4046+
return matchDeepTypeArguments(*this, subflags, args1, args2, baseLoc);
4047+
40424048
auto argMatchingFlags = subflags;
40434049
// Allow the solver to produce separate fixes while matching
40444050
// key path's root/value to a contextual type instead of the
@@ -4049,13 +4055,6 @@ ConstraintSystem::matchDeepEqualityTypes(Type type1, Type type2,
40494055
argMatchingFlags |= TMF_MatchingGenericArguments;
40504056
}
40514057

4052-
// Optionals have a lot of special diagnostics and only one
4053-
// generic argument so if we' re dealing with one, don't produce generic
4054-
// arguments mismatch fixes.
4055-
if (bound1->getDecl()->isOptionalDecl())
4056-
return matchDeepTypeArguments(*this, argMatchingFlags, args1, args2,
4057-
baseLoc);
4058-
40594058
SmallVector<unsigned, 4> mismatches;
40604059
auto result = matchDeepTypeArguments(
40614060
*this, argMatchingFlags, args1, args2, baseLoc,

0 commit comments

Comments
 (0)