Skip to content

Commit 48c5786

Browse files
committed
Disregard any reference storage types when inferring associated types from
witnesses. SR-6097.
1 parent 9c52678 commit 48c5786

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3991,7 +3991,7 @@ static Type getWitnessTypeForMatching(TypeChecker &tc,
39913991
Type model = conformance->getType();
39923992
TypeSubstitutionMap substitutions = model->getMemberSubstitutions(witness);
39933993
if (substitutions.empty())
3994-
return witness->getInterfaceType();
3994+
return witness->getInterfaceType()->getReferenceStorageReferent();
39953995

39963996
Type type = witness->getInterfaceType();
39973997

test/Generics/associated_types.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,25 @@ extension M {
199199
_ = B.A.isP
200200
}
201201
}
202+
203+
// SR-6097
204+
protocol sr6097 {
205+
associatedtype A : AnyObject
206+
var aProperty: A { get }
207+
}
208+
209+
class C1 {}
210+
class C2 : sr6097 {
211+
unowned let aProperty: C1 // should deduce A == C1 despite 'unowned'
212+
init() { fatalError() }
213+
}
214+
215+
protocol sr6097_b {
216+
associatedtype A : AnyObject
217+
var aProperty: A? { get }
218+
}
219+
class C3 : sr6097_b {
220+
weak var aProperty: C1? // and same here, despite 'weak'
221+
init() { fatalError() }
222+
}
223+

0 commit comments

Comments
 (0)