Skip to content

Commit 25e1bb5

Browse files
committed
[CSApply] Filter out functions and instance members before the ambiguous none check
1 parent 8d869e6 commit 25e1bb5

File tree

2 files changed

+51
-8
lines changed

2 files changed

+51
-8
lines changed

lib/Sema/CSApply.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,19 +2475,24 @@ namespace {
24752475
baseTyUnwrapped,
24762476
memberName,
24772477
defaultMemberLookupOptions);
2478-
2479-
// Lookup didn't find anything, so return
2478+
2479+
// Filter out any functions or instance members
2480+
results.filter([](const LookupResultEntry entry, bool isOuter) {
2481+
if (auto member = entry.getValueDecl()) {
2482+
if (isa<FuncDecl>(member))
2483+
return false;
2484+
if (member->isInstanceMember())
2485+
return false;
2486+
}
2487+
2488+
return true;
2489+
});
2490+
24802491
if (results.empty()) {
24812492
return;
24822493
}
24832494

24842495
if (auto member = results.front().getValueDecl()) {
2485-
// Lookup returned a member that is an instance member,
2486-
// so return
2487-
if (member->isInstanceMember()) {
2488-
return;
2489-
}
2490-
24912496
// If we have something like 'static let none = 1', then ignore.
24922497
if (auto VD = dyn_cast<VarDecl>(member)) {
24932498
if (!VD->getInterfaceType()->isEqual(

test/decl/enum/enumtest.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,45 @@ enum EnumWithStaticNone2 {
455455
static let none = EnumWithStaticNone2.a
456456
}
457457

458+
enum EnumWithStaticNone3 {
459+
case a
460+
static let none = EnumWithStaticNone3.a
461+
var none: EnumWithStaticNone3 { return .a }
462+
}
463+
464+
enum EnumWithStaticNone4 {
465+
case a
466+
var none: EnumWithStaticNone4 { return .a }
467+
static let none = EnumWithStaticNone4.a
468+
}
469+
470+
enum EnumWithStaticFuncNone1 {
471+
case a
472+
static func none() -> Int { return 1 }
473+
}
474+
475+
enum EnumWithStaticFuncNone2 {
476+
case a
477+
static func none() -> EnumWithStaticFuncNone2 { return .a }
478+
}
479+
480+
/// Make sure we don't diagnose 'static let none = 1', but do diagnose 'static let none = TheEnum.anotherCase' ///
481+
458482
let _: EnumWithStaticNone1? = .none // Okay
459483
let _: EnumWithStaticNone2? = .none // expected-warning {{assuming you mean 'Optional<EnumWithStaticNone2>.none'; did you mean 'EnumWithStaticNone2.none' instead?}}
460484
// expected-note@-1 {{explicitly specify 'Optional' to silence this warning}}{{31-31=Optional}}
461485
// expected-note@-2 {{use 'EnumWithStaticNone2.none' instead}}{{31-31=EnumWithStaticNone2}}
486+
487+
/// Make sure we diagnose if we have both static and instance 'none' member regardless of source order ///
488+
489+
let _: EnumWithStaticNone3? = .none // expected-warning {{assuming you mean 'Optional<EnumWithStaticNone3>.none'; did you mean 'EnumWithStaticNone3.none' instead?}}
490+
// expected-note@-1 {{explicitly specify 'Optional' to silence this warning}}{{31-31=Optional}}
491+
// expected-note@-2 {{use 'EnumWithStaticNone3.none' instead}}{{31-31=EnumWithStaticNone3}}
492+
let _: EnumWithStaticNone4? = .none // expected-warning {{assuming you mean 'Optional<EnumWithStaticNone4>.none'; did you mean 'EnumWithStaticNone4.none' instead?}}
493+
// expected-note@-1 {{explicitly specify 'Optional' to silence this warning}}{{31-31=Optional}}
494+
// expected-note@-2 {{use 'EnumWithStaticNone4.none' instead}}{{31-31=EnumWithStaticNone4}}
495+
496+
/// Make sure we don't diagnose 'static func none -> T' ///
497+
498+
let _: EnumWithStaticFuncNone1? = .none // Okay
499+
let _: EnumWithStaticFuncNone2? = .none // Okay

0 commit comments

Comments
 (0)