Skip to content

Commit a537e04

Browse files
committed
Break Another Overload Resolution Cycle
Resolve a cycle caused by overload resolution considering recursive static candidates where before it would silently reject them. In a world before the InterfaceTypeRequest, the overload resolution machinery would attempt to validate the declaration and would recieve a bad answer. This caused circular candidates to be ignored as a side effect. This behavior was partially restored by the fixes in #27725 and #27668 but that isn't enough for recursive static variables. Even if it were, the constraint fix kind doesn't make sense. Luckily, the right answer is to just reject recursive static VarDecl candidates entirely. Addresses rdar://56410015
1 parent 0086eb0 commit a537e04

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4970,8 +4970,13 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
49704970
if (auto *PBI = dyn_cast<PatternBindingInitializer>(DC)) {
49714971
if (auto *VD = dyn_cast<VarDecl>(decl)) {
49724972
if (PBI->getBinding() == VD->getParentPatternBinding()) {
4973-
result.addUnviable(candidate,
4974-
MemberLookupResult::UR_InstanceMemberOnType);
4973+
// If this is a recursive reference to an instance variable,
4974+
// try to see if we can give a good diagnostic by adding it as
4975+
// an unviable candidate.
4976+
if (!VD->isStatic()) {
4977+
result.addUnviable(candidate,
4978+
MemberLookupResult::UR_InstanceMemberOnType);
4979+
}
49754980
return;
49764981
}
49774982
}

test/decl/circularity.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,15 @@ class Sub: Base {
4343
return foo(1) // expected-error {{variable used within its own initial value}}
4444
}()
4545
}
46+
47+
extension Float {
48+
static let pickMe: Float = 1
49+
}
50+
51+
extension SIMD3 {
52+
init(_ scalar: Scalar) { self.init(repeating: scalar) }
53+
}
54+
55+
extension SIMD3 where SIMD3.Scalar == Float {
56+
static let pickMe = SIMD3(.pickMe)
57+
}

0 commit comments

Comments
 (0)