Skip to content

Commit 9d21fbb

Browse files
committed
[CS] Don't try inout-to-ptr for array to raw ptr
Array-to-pointer should only be used for such conversions. This isn't currently an issue as we short-circuit disjunctions upon successfully solving an array-to-pointer conversion. However this would become an issue if only inout-to-pointer was viable.
1 parent 2759ae2 commit 9d21fbb

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3718,18 +3718,22 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
37183718
if (!isAutoClosureArgument) {
37193719
auto inoutBaseType = inoutType1->getInOutObjectType();
37203720

3721-
Type simplifiedInoutBaseType = getFixedTypeRecursive(
3722-
inoutBaseType, /*wantRValue=*/true);
3721+
auto baseIsArray = isArrayType(
3722+
getFixedTypeRecursive(inoutBaseType, /*wantRValue=*/true));
37233723

37243724
// FIXME: If the base is still a type variable, we can't tell
37253725
// what to do here. Might have to try \c ArrayToPointer and make
37263726
// it more robust.
3727-
if (isArrayType(simplifiedInoutBaseType)) {
3727+
if (baseIsArray)
37283728
conversionsOrFixes.push_back(
37293729
ConversionRestrictionKind::ArrayToPointer);
3730-
}
3731-
conversionsOrFixes.push_back(
3732-
ConversionRestrictionKind::InoutToPointer);
3730+
3731+
// Only try an inout-to-pointer conversion if we know it's not
3732+
// an array being converted to a raw pointer type. Such
3733+
// conversions can only use array-to-pointer.
3734+
if (!baseIsArray || !isRawPointerKind(pointerKind))
3735+
conversionsOrFixes.push_back(
3736+
ConversionRestrictionKind::InoutToPointer);
37333737
}
37343738
}
37353739

0 commit comments

Comments
 (0)