Skip to content

Commit 20d9838

Browse files
committed
Sema: Generalize analysis of same-type requirements of protocol extension witnesses
Fixes rdar://problem/122606610.
1 parent 373f7e3 commit 20d9838

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

lib/Sema/AssociatedTypeInference.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,18 +1443,22 @@ static InferenceCandidateKind checkInferenceCandidate(
14431443
}
14441444

14451445
if (auto otherAssoc = other->getAs<DependentMemberType>()) {
1446-
if (otherAssoc->getBase()->isEqual(selfTy)) {
1447-
DependentMemberType *otherDMT;
1448-
if (ctx.LangOpts.EnableExperimentalAssociatedTypeInference) {
1446+
if (ctx.LangOpts.EnableExperimentalAssociatedTypeInference) {
14491447

1450-
otherDMT = otherAssoc;
1451-
1452-
} else {
1448+
result->second = result->second.transform([&](Type t) -> Type{
1449+
if (t->isEqual(dmt))
1450+
return otherAssoc;
1451+
return t;
1452+
});
1453+
LLVM_DEBUG(llvm::dbgs() << "++ we can same-type to:\n";
1454+
result->second->dump(llvm::dbgs()));
1455+
return InferenceCandidateKind::Good;
14531456

1454-
otherDMT = DependentMemberType::get(dmt->getBase(),
1455-
otherAssoc->getAssocType());
1457+
} else {
14561458

1457-
}
1459+
if (otherAssoc->getBase()->isEqual(selfTy)) {
1460+
auto *otherDMT = DependentMemberType::get(dmt->getBase(),
1461+
otherAssoc->getAssocType());
14581462

14591463
result->second = result->second.transform([&](Type t) -> Type{
14601464
if (t->isEqual(dmt))
@@ -1465,6 +1469,8 @@ static InferenceCandidateKind checkInferenceCandidate(
14651469
result->second->dump(llvm::dbgs()));
14661470
return InferenceCandidateKind::Good;
14671471
}
1472+
1473+
}
14681474
}
14691475
break;
14701476
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %target-typecheck-verify-swift -disable-experimental-associated-type-inference
2+
// RUN: %target-typecheck-verify-swift -enable-experimental-associated-type-inference
3+
4+
public protocol P<A> {
5+
associatedtype A
6+
associatedtype B: P
7+
8+
func makeA() -> A
9+
var b: B { get }
10+
}
11+
12+
extension P where A == B.A {
13+
public func makeA() -> B.A {
14+
fatalError()
15+
}
16+
}
17+
18+
public struct S: P {
19+
public var b: some P<Int> {
20+
return G<Int>()
21+
}
22+
}
23+
24+
public struct G<A>: P {
25+
public func makeA() -> A { fatalError() }
26+
public var b: Never { fatalError() }
27+
}
28+
29+
extension Never: P {
30+
public func makeA() -> Never { fatalError() }
31+
public var b: Never { fatalError() }
32+
}

0 commit comments

Comments
 (0)