Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3991,7 +3991,7 @@ static Type getWitnessTypeForMatching(TypeChecker &tc,
Type model = conformance->getType();
TypeSubstitutionMap substitutions = model->getMemberSubstitutions(witness);
if (substitutions.empty())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the witness is in a generic context? Eg,

class G<T> : SomeProto where T : AnyObject {
  weak var t: T?
}

return witness->getInterfaceType();
return witness->getInterfaceType()->getReferenceStorageReferent();

Type type = witness->getInterfaceType();

Expand Down
22 changes: 22 additions & 0 deletions test/Generics/associated_types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,25 @@ extension M {
_ = B.A.isP
}
}

// SR-6097
protocol sr6097 {
associatedtype A : AnyObject
var aProperty: A { get }
}

class C1 {}
class C2 : sr6097 {
unowned let aProperty: C1 // should deduce A == C1 despite 'unowned'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you actually know it's deducing this?

init() { fatalError() }
}

protocol sr6097_b {
associatedtype A : AnyObject
var aProperty: A? { get }
}
class C3 : sr6097_b {
weak var aProperty: C1? // and same here, despite 'weak'
init() { fatalError() }
}