Skip to content

Commit 3ebd53d

Browse files
committed
AST: Name lookup shouldn't filter out static/instance methods from instance/static context
We do this in a more general way higher up in the constraint solver. Filtering out methods in name lookup only hurts diagnostics. In fact I don't think this behavior was intentional at all, since the code in question was originally written in 2013 before a lot of the more recent member lookup and diagnostic code was added. This does break source compatibility though, but in a minor way. See the change to the CoreGraphics overlay. Again, though, I think this was an accident and not intentional.
1 parent 522f4e4 commit 3ebd53d

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

lib/AST/NameLookup.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -556,15 +556,8 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
556556

557557
SmallVector<ValueDecl *, 4> Lookup;
558558
DC->lookupQualified(ExtendedType, Name, options, TypeResolver, Lookup);
559-
bool isMetatypeType = ExtendedType->is<AnyMetatypeType>();
560559
bool FoundAny = false;
561560
for (auto Result : Lookup) {
562-
// If we're looking into an instance, skip static functions.
563-
if (!isMetatypeType &&
564-
isa<FuncDecl>(Result) &&
565-
cast<FuncDecl>(Result)->isStatic())
566-
continue;
567-
568561
// Classify this declaration.
569562
FoundAny = true;
570563

@@ -575,12 +568,6 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
575568
else
576569
Results.push_back(UnqualifiedLookupResult(MetaBaseDecl, Result));
577570
continue;
578-
} else if (auto FD = dyn_cast<FuncDecl>(Result)) {
579-
if (FD->isStatic() && !isMetatypeType)
580-
continue;
581-
} else if (isa<EnumElementDecl>(Result)) {
582-
Results.push_back(UnqualifiedLookupResult(BaseDecl, Result));
583-
continue;
584571
}
585572

586573
Results.push_back(UnqualifiedLookupResult(BaseDecl, Result));

stdlib/public/SDK/CoreGraphics/CGFloat.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public struct CGFloat {
175175
}
176176

177177
public var magnitude: CGFloat {
178-
return CGFloat(abs(native))
178+
return CGFloat(Swift.abs(native))
179179
}
180180

181181
public mutating func negate() {

test/expr/primary/unqualified_name.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ struct S0 {
2828
_ = self.f0(:y:z:) // expected-error{{an empty argument label is spelled with '_'}}{{17-17=_}}
2929
_ = self.f1(_:`while`:) // expected-warning{{keyword 'while' does not need to be escaped in argument list}}{{19-20=}}{{25-26=}}
3030
_ = self.f2(_:`let`:)
31+
32+
_ = f3(_:y:z:) // expected-error{{static member 'f3(_:y:z:)' cannot be used on instance of type 'S0'}}
33+
}
34+
35+
static func testStaticS0() {
36+
_ = f0(_:y:z:)
37+
_ = f3(_:y:z:)
3138
}
3239

3340
static func f3(_ x: Int, y: Int, z: Int) -> S0 { return S0() }

test/expr/unary/selector/property.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ObjCClass {
3737
let _ = #selector(setter: myConstant) // expected-error {{argument of '#selector(setter:)' refers to non-settable let 'myConstant'}}
3838
let _ = #selector(setter: myComputedReadOnlyProperty) // expected-error {{argument of '#selector(setter:)' refers to non-settable var 'myComputedReadOnlyProperty'}}
3939

40-
let _ = #selector(myClassFunc) // expected-error{{use of unresolved identifier 'myClassFunc'}}
40+
let _ = #selector(myClassFunc) // expected-error{{static member 'myClassFunc' cannot be used on instance of type 'ObjCClass'}}
4141
}
4242

4343
class func classMethod() {
@@ -173,7 +173,7 @@ class InstanceStaticTestClass {
173173

174174
@objc static func staticMethod() {}
175175

176-
@objc func instanceMethod() {} // expected-note {{did you mean 'instanceMethod'?}}
176+
@objc func instanceMethod() {}
177177

178178
@objc func instanceAndStaticMethod() {}
179179
@objc class func instanceAndStaticMethod() {}
@@ -205,8 +205,8 @@ class InstanceStaticTestClass {
205205
let _ = #selector(instanceMethod)
206206

207207
let _ = #selector(getter: staticProperty) // expected-error{{static member 'staticProperty' cannot be used on instance of type 'InstanceStaticTestClass'}}
208-
let _ = #selector(classMethod) // expected-error{{use of unresolved identifier 'classMethod'}}
209-
let _ = #selector(staticMethod) // expected-error{{use of unresolved identifier 'staticMethod'}}
208+
let _ = #selector(classMethod) // expected-error{{static member 'classMethod' cannot be used on instance of type 'InstanceStaticTestClass'}}
209+
let _ = #selector(staticMethod) // expected-error{{static member 'staticMethod' cannot be used on instance of type 'InstanceStaticTestClass'}}
210210

211211
let _ = #selector(instanceAndStaticMethod)
212212
}

0 commit comments

Comments
 (0)