Skip to content

Commit 79f6b07

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`.
1 parent b7a7839 commit 79f6b07

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
@@ -1846,6 +1846,9 @@ class Solution {
18461846
/// locator.
18471847
ArgumentList *getArgumentList(ConstraintLocator *locator) const;
18481848

1849+
std::optional<ConversionRestrictionKind>
1850+
getConversionRestriction(CanType type1, CanType type2) const;
1851+
18491852
SWIFT_DEBUG_DUMP;
18501853

18511854
/// Dump this solution.

lib/Sema/CSApply.cpp

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

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

lib/Sema/ConstraintSystem.cpp

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

3969+
std::optional<ConversionRestrictionKind>
3970+
Solution::getConversionRestriction(CanType type1, CanType type2) const {
3971+
auto restriction = ConstraintRestrictions.find({type1, type2});
3972+
if (restriction != ConstraintRestrictions.end())
3973+
return restriction->second;
3974+
return std::nullopt;
3975+
}
3976+
39693977
#ifndef NDEBUG
39703978
/// Given an apply expr, returns true if it is expected to have a direct callee
39713979
/// overload, resolvable using `getChoiceFor`. Otherwise, returns false.

0 commit comments

Comments
 (0)