Skip to content

Commit ce4b29e

Browse files
committed
Sema: Fix logic error in TypeReprCycleCheckWalker handling of 'Self.Foo'
We don't want to throw out a witness if it has any mention of 'Self.Foo'; we must also check that 'Foo' is one of the associated types being inferred. Otherwise, it may be a protocol type alias, in which case we want to proceed with the witness. This fixes a regression from a recent change, a576984. Fixes rdar://problem/120743365.
1 parent e24c9a8 commit ce4b29e

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/Sema/TypeCheckProtocolInference.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ struct TypeReprCycleCheckWalker : ASTWalker {
212212

213213
// If we're inferring `Foo`, don't look at a witness mentioning `Self.Foo`.
214214
if (auto *identTyR = dyn_cast<SimpleIdentTypeRepr>(baseTyR)) {
215-
if (identTyR->getNameRef().getBaseIdentifier() == ctx.Id_Self) {
215+
if (identTyR->getNameRef().getBaseIdentifier() == ctx.Id_Self &&
216+
circularNames.count(memberTyR->getNameRef().getBaseIdentifier()) > 0) {
216217
// But if qualified lookup can find a type with this name without
217218
// looking into protocol members, don't skip the witness, since this
218219
// type might be a candidate witness.

test/decl/protocol/req/assoc_type_inference_cycle.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,19 @@ public struct LogTypes: OptionSet {
131131

132132
public let rawValue: Int
133133
}
134+
135+
// rdar://120743365
136+
public struct G<T> {}
137+
138+
public protocol HasAlias {
139+
typealias A = G<Self>
140+
associatedtype B
141+
142+
func f1(_: Self.A, _: Self.B)
143+
func f2(_: Self.A, _: Self.B)
144+
}
145+
146+
public struct ConformsHasAlias: HasAlias {
147+
public func f1(_: Self.A, _: Self.B) {}
148+
public func f2(_: Self.A, _: Int) {}
149+
}

0 commit comments

Comments
 (0)