Skip to content

Commit 7fb27b3

Browse files
committed
[ConstraintSystem] Find solutions for code that contains circular member
references in the new diagnostic infrastructure.
1 parent 86cf6dc commit 7fb27b3

File tree

3 files changed

+16
-27
lines changed

3 files changed

+16
-27
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5461,22 +5461,9 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
54615461
auto addChoice = [&](OverloadChoice candidate) {
54625462
auto decl = candidate.getDecl();
54635463

5464-
// In a pattern binding initializer, immediately reject all of its bound
5465-
// variables. These would otherwise allow circular references.
5466-
if (auto *PBI = dyn_cast<PatternBindingInitializer>(DC)) {
5467-
if (auto *VD = dyn_cast<VarDecl>(decl)) {
5468-
if (PBI->getBinding() == VD->getParentPatternBinding()) {
5469-
// If this is a recursive reference to an instance variable,
5470-
// try to see if we can give a good diagnostic by adding it as
5471-
// an unviable candidate.
5472-
if (!VD->isStatic()) {
5473-
result.addUnviable(candidate,
5474-
MemberLookupResult::UR_InstanceMemberOnType);
5475-
}
5476-
return;
5477-
}
5478-
}
5479-
}
5464+
// Reject circular references immediately.
5465+
if (decl->isRecursiveValidation())
5466+
return;
54805467

54815468
// If the result is invalid, skip it.
54825469
if (decl->isInvalid()) {

test/NameBinding/name_lookup.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -619,20 +619,18 @@ struct PatternBindingWithTwoVars2 { var x = y, y = 3 }
619619
// expected-error@-1 {{cannot use instance member 'y' within property initializer; property initializers run before 'self' is available}}
620620

621621
struct PatternBindingWithTwoVars3 { var x = y, y = x }
622-
// expected-error@-1 {{cannot use instance member 'x' within property initializer; property initializers run before 'self' is available}}
623-
// expected-error@-2 {{cannot use instance member 'y' within property initializer; property initializers run before 'self' is available}}
624-
// expected-error@-3 {{circular reference}}
622+
// expected-error@-1 {{circular reference}}
623+
// expected-note@-2 {{through reference here}}
624+
// expected-note@-3 {{through reference here}}
625625
// expected-note@-4 {{through reference here}}
626626
// expected-note@-5 {{through reference here}}
627627
// expected-note@-6 {{through reference here}}
628-
// expected-note@-7 {{through reference here}}
628+
// expected-error@-7 {{circular reference}}
629629
// expected-note@-8 {{through reference here}}
630-
// expected-error@-9 {{circular reference}}
630+
// expected-note@-9 {{through reference here}}
631631
// expected-note@-10 {{through reference here}}
632632
// expected-note@-11 {{through reference here}}
633633
// expected-note@-12 {{through reference here}}
634-
// expected-note@-13 {{through reference here}}
635-
// expected-note@-14 {{through reference here}}
636634

637635
// https://bugs.swift.org/browse/SR-9015
638636
func sr9015() {

test/decl/overload.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,23 +577,27 @@ enum SR_10084_E_8 {
577577
}
578578

579579
enum SR_10084_E_9 {
580-
case A // expected-note {{'A' previously declared here}}
580+
case A // expected-note {{'A' previously declared here}} expected-note {{found this candidate}}
581581
static let A: SR_10084_E_9 = .A // expected-error {{invalid redeclaration of 'A'}}
582+
// expected-error@-1 {{ambiguous use of 'A'}} expected-note@-1 {{found this candidate}}
582583
}
583584

584585
enum SR_10084_E_10 {
585586
static let A: SR_10084_E_10 = .A // expected-note {{'A' previously declared here}}
586-
case A // expected-error {{invalid redeclaration of 'A'}}
587+
// expected-error@-1 {{ambiguous use of 'A'}} expected-note@-1 {{found this candidate}}
588+
case A // expected-error {{invalid redeclaration of 'A'}} expected-note {{found this candidate}}
587589
}
588590

589591
enum SR_10084_E_11 {
590-
case A // expected-note {{'A' previously declared here}}
592+
case A // expected-note {{'A' previously declared here}} expected-note {{found this candidate}}
591593
static var A: SR_10084_E_11 = .A // expected-error {{invalid redeclaration of 'A'}}
594+
// expected-error@-1 {{ambiguous use of 'A'}} expected-note@-1 {{found this candidate}}
592595
}
593596

594597
enum SR_10084_E_12 {
595598
static var A: SR_10084_E_12 = .A // expected-note {{'A' previously declared here}}
596-
case A // expected-error {{invalid redeclaration of 'A'}}
599+
// expected-error@-1 {{ambiguous use of 'A'}} expected-note@-1 {{found this candidate}}
600+
case A // expected-error {{invalid redeclaration of 'A'}} expected-note {{found this candidate}}
597601
}
598602

599603
enum SR_10084_E_13 {

0 commit comments

Comments
 (0)