Skip to content

Commit 751609c

Browse files
xedinhborla
authored andcommitted
Make repairViaOptionalUnwrap less eager
If the source of the "mismatch" is `Equal` constraint we can't record a missing unwrap fix if either size is a type variable after all of the optionals have been stripped away because there is not enough information about what is expected behavior until type variable gets bound.
1 parent 61cb9a5 commit 751609c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2958,6 +2958,19 @@ repairViaOptionalUnwrap(ConstraintSystem &cs, Type fromType, Type toType,
29582958
std::tie(fromObjectType, fromUnwraps) = getObjectTypeAndUnwraps(fromType);
29592959
std::tie(toObjectType, toUnwraps) = getObjectTypeAndUnwraps(toType);
29602960

2961+
// Since equality is symmetric and it decays into a `Bind` eagerly
2962+
// unwrapping optionals from either side might be incorrect since
2963+
// there is not enough information about what is expected e.g.
2964+
// `Int?? equal T0?` just like `T0? equal Int??` allows `T0` to be
2965+
// bound to `Int?` and there is no need to unwrap. Solver has to wait
2966+
// until more information becomes available about what `T0` is expected
2967+
// to be before taking action.
2968+
if (matchKind == ConstraintKind::Equal &&
2969+
(fromObjectType->is<TypeVariableType>() ||
2970+
toObjectType->is<TypeVariableType>())) {
2971+
return false;
2972+
}
2973+
29612974
// If `from` is not less optional than `to`, force unwrap is
29622975
// not going to help here. In case of object type of `from`
29632976
// is a type variable, let's assume that it might be optional.

0 commit comments

Comments
 (0)