Skip to content

Commit d29ec92

Browse files
committed
[5.1][Sema] Treat static methods as always applying self
Currently `areConservativelyCompatibleArgumentLabels` treats a reference to a declaration as not applying its curried self parameter if it doesn't have a base type. However this isn't correct for static operators, which have their Self.Type parameter applied but don't have a base type. This commit changes `areConservativelyCompatibleArgumentLabels` to always treat static methods as having their Self.Type parameters applied, as there's currently no way to form an unapplied curried reference to them. Resolves SR-10843.
1 parent e5cad29 commit d29ec92

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ bool constraints::areConservativelyCompatibleArgumentLabels(
130130
bool hasCurriedSelf;
131131
if (isa<SubscriptDecl>(decl)) {
132132
hasCurriedSelf = false;
133+
} else if (decl->isStatic() && isa<AbstractFunctionDecl>(decl)) {
134+
// Static methods always have their Self.Type parameter applied.
135+
hasCurriedSelf = true;
133136
} else if (!baseType || baseType->is<ModuleType>()) {
134137
hasCurriedSelf = false;
135138
} else if (baseType->is<AnyMetatypeType>() && decl->isInstanceMember()) {

test/Constraints/operator.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,17 @@ func rdar46459603() {
223223
_ = [arr.values] == [[e]]
224224
// expected-error@-1 {{protocol type 'Any' cannot conform to 'Equatable' because only concrete types can conform to protocols}}
225225
}
226+
227+
// SR-10843
228+
infix operator ^^^
229+
func ^^^ (lhs: String, rhs: String) {}
230+
231+
struct SR10843 {
232+
static func ^^^ (lhs: SR10843, rhs: SR10843) {}
233+
}
234+
235+
func sr10843() {
236+
let s = SR10843()
237+
(^^^)(s, s)
238+
_ = (==)(0, 0)
239+
}

0 commit comments

Comments
 (0)