Skip to content

Commit d95e92c

Browse files
committed
[CSSimplify] Allow implicit Swift -> C pointer conversion within optional types
Support Swift -> C pointer conversions even if argument required a value to optional promotion or is optional.
1 parent 621ea81 commit d95e92c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5894,7 +5894,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
58945894
//
58955895
// Do some light verification before recording restriction to
58965896
// avoid allocating constraints for obviously invalid cases.
5897-
if (type1IsPointer && !type1IsOptional && !type2IsOptional &&
5897+
if (type1IsPointer && optionalityMatches &&
58985898
isArgumentOfImportedDecl(locator)) {
58995899
// UnsafeRawPointer -> UnsafePointer<[U]Int8>
59005900
if (type1PointerKind == PTK_UnsafeRawPointer &&
@@ -11157,8 +11157,12 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
1115711157

1115811158
PointerTypeKind swiftPtrKind, cPtrKind;
1115911159

11160-
auto swiftPtr = type1->getAnyPointerElementType(swiftPtrKind);
11161-
auto cPtr = type2->getAnyPointerElementType(cPtrKind);
11160+
auto swiftPtr =
11161+
type1->lookThroughAllOptionalTypes()->getAnyPointerElementType(
11162+
swiftPtrKind);
11163+
11164+
auto cPtr = type2->lookThroughAllOptionalTypes()->getAnyPointerElementType(
11165+
cPtrKind);
1116211166

1116311167
// Unsafe[Mutable]RawPointer -> Unsafe[Mutable]Pointer<[U]Int8>
1116411168
if (swiftPtrKind == PTK_UnsafeRawPointer ||

0 commit comments

Comments
 (0)