Skip to content

Commit a7fbc04

Browse files
committed
[CSSimplify] PointerToCPointer: Allow element type inference for "argument" pointers
If the type of the "argument" pointer is not yet resolved the solver should equate it to that of the "parameter" pointer as regular conversions do.
1 parent e4eb271 commit a7fbc04

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13768,6 +13768,19 @@ ConstraintSystem::simplifyPointerToCPointerRestriction(
1376813768
return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
1376913769
};
1377013770

13771+
auto elementLoc = locator.withPathElement(LocatorPathElt::GenericArgument(0));
13772+
13773+
if (swiftPtr->isTypeVariableOrMember()) {
13774+
// Inference between the equivalent pointer kinds is
13775+
// handled by regular pointer conversions.
13776+
if (swiftPtrKind == cPtrKind)
13777+
return SolutionKind::Error;
13778+
13779+
addConstraint(ConstraintKind::BindToPointerType, swiftPtr, cPtr,
13780+
elementLoc);
13781+
return markSupported();
13782+
}
13783+
1377113784
// If pointers have the same element type there is nothing to do.
1377213785
if (swiftPtr->isEqual(cPtr))
1377313786
return markSupported();
@@ -13783,15 +13796,10 @@ ConstraintSystem::simplifyPointerToCPointerRestriction(
1378313796
// Unsafe[Mutable]Pointer<T> -> Unsafe[Mutable]Pointer<[U]Int8>
1378413797
if (cPtr->isInt8() || cPtr->isUInt8()) {
1378513798
// <T> can default to the type of C pointer.
13786-
addConstraint(
13787-
ConstraintKind::Defaultable, swiftPtr, cPtr,
13788-
locator.withPathElement(LocatorPathElt::GenericArgument(0)));
13799+
addConstraint(ConstraintKind::Defaultable, swiftPtr, cPtr, elementLoc);
1378913800
return markSupported();
1379013801
}
1379113802

13792-
auto elementLoc =
13793-
locator.withPathElement(LocatorPathElt::GenericArgument(0));
13794-
1379513803
// Unsafe[Mutable]Pointer<Int{8, 16, ...}> <->
1379613804
// Unsafe[Mutable]Pointer<UInt{8, 16, ...}>
1379713805
if (swiftPtr->isInt() || swiftPtr->isUInt()) {

0 commit comments

Comments
 (0)