Skip to content

Commit fc4f4c4

Browse files
committed
[CSApply] Mark self parameter as inout when base/self match on deep equality
If type equality check fails we need to check whether the types are the same with deep equality restriction since `any Sendable` to `Any` conversion is now supported in generic argument positions of @preconcurrency declarations. i.e. referencing a member on `[any Sendable]` if member declared in an extension that expects `Element` to be equal to `Any`. (cherry picked from commit 79f6b07)
1 parent 33e091c commit fc4f4c4

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,9 @@ class Solution {
18271827
/// locator.
18281828
ArgumentList *getArgumentList(ConstraintLocator *locator) const;
18291829

1830+
std::optional<ConversionRestrictionKind>
1831+
getConversionRestriction(CanType type1, CanType type2) const;
1832+
18301833
SWIFT_DEBUG_DUMP;
18311834

18321835
/// Dump this solution.

lib/Sema/CSApply.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1719,7 +1719,16 @@ namespace {
17191719
// pass it as an inout qualified type.
17201720
auto selfParamTy = isDynamic ? selfTy : containerTy;
17211721

1722-
if (selfTy->isEqual(baseTy))
1722+
// If type equality check fails we need to check whether the types
1723+
// are the same with deep equality restriction since `any Sendable`
1724+
// to `Any` conversion is now supported in generic argument positions
1725+
// of @preconcurrency declarations. i.e. referencing a member on
1726+
// `[any Sendable]` if member declared in an extension that expects
1727+
// `Element` to be equal to `Any`.
1728+
if (selfTy->isEqual(baseTy) ||
1729+
solution.getConversionRestriction(baseTy->getCanonicalType(),
1730+
selfTy->getCanonicalType()) ==
1731+
ConversionRestrictionKind::DeepEquality)
17231732
if (cs.getType(base)->is<LValueType>())
17241733
selfParamTy = InOutType::get(selfTy);
17251734

lib/Sema/ConstraintSystem.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3948,6 +3948,14 @@ ArgumentList *Solution::getArgumentList(ConstraintLocator *locator) const {
39483948
return nullptr;
39493949
}
39503950

3951+
std::optional<ConversionRestrictionKind>
3952+
Solution::getConversionRestriction(CanType type1, CanType type2) const {
3953+
auto restriction = ConstraintRestrictions.find({type1, type2});
3954+
if (restriction != ConstraintRestrictions.end())
3955+
return restriction->second;
3956+
return std::nullopt;
3957+
}
3958+
39513959
#ifndef NDEBUG
39523960
/// Given an apply expr, returns true if it is expected to have a direct callee
39533961
/// overload, resolvable using `getChoiceFor`. Otherwise, returns false.

0 commit comments

Comments
 (0)