Skip to content

Commit 8d869e6

Browse files
committed
[CSApply] Don't diagnose a 'static let none' as ambiguous none unless its type matches the enum
1 parent 56edd08 commit 8d869e6

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

lib/Sema/CSApply.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2487,7 +2487,14 @@ namespace {
24872487
if (member->isInstanceMember()) {
24882488
return;
24892489
}
2490-
2490+
2491+
// If we have something like 'static let none = 1', then ignore.
2492+
if (auto VD = dyn_cast<VarDecl>(member)) {
2493+
if (!VD->getInterfaceType()->isEqual(
2494+
baseTyNominalDecl->getDeclaredInterfaceType()))
2495+
return;
2496+
}
2497+
24912498
// Return if the member is an enum case w/ assoc values, as we only
24922499
// care (for now) about cases with no assoc values (like none)
24932500
if (auto EED = dyn_cast<EnumElementDecl>(member)) {

test/decl/enum/enumtest.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,4 +441,21 @@ class C {}
441441
protocol P {}
442442

443443
enum E : C & P {}
444-
// expected-error@-1 {{inheritance from class-constrained protocol composition type 'C & P'}}
444+
// expected-error@-1 {{inheritance from class-constrained protocol composition type 'C & P'}}
445+
446+
// SR-11522
447+
448+
enum EnumWithStaticNone1 {
449+
case a
450+
static let none = 1
451+
}
452+
453+
enum EnumWithStaticNone2 {
454+
case a
455+
static let none = EnumWithStaticNone2.a
456+
}
457+
458+
let _: EnumWithStaticNone1? = .none // Okay
459+
let _: EnumWithStaticNone2? = .none // expected-warning {{assuming you mean 'Optional<EnumWithStaticNone2>.none'; did you mean 'EnumWithStaticNone2.none' instead?}}
460+
// expected-note@-1 {{explicitly specify 'Optional' to silence this warning}}{{31-31=Optional}}
461+
// expected-note@-2 {{use 'EnumWithStaticNone2.none' instead}}{{31-31=EnumWithStaticNone2}}

0 commit comments

Comments
 (0)