Skip to content

Commit b9f1e58

Browse files
committed
[CodeCompletion] Use GenericSignature methods to get associatedtype reqs
1 parent 1dd6fe5 commit b9f1e58

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4201,28 +4201,21 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
42014201
// If resolved print it.
42024202
return nullptr;
42034203

4204-
// Collect requirements on the associatedtype.
4205-
ProtocolDecl *protoD =
4206-
ResultT->castTo<DependentMemberType>()->getAssocType()->getProtocol();
4204+
auto genericSig = VD->getDeclContext()->getGenericSignatureOfContext();
4205+
4206+
if (genericSig->isConcreteType(ResultT))
4207+
// If it has same type requrement, we will emit the concrete type.
4208+
return nullptr;
42074209

4210+
// Collect requirements on the associatedtype.
42084211
SmallVector<Type, 2> opaqueTypes;
42094212
bool hasExplicitAnyObject = false;
4210-
for (auto req : protoD->getRequirementSignature()) {
4211-
if (!req.getFirstType()->isEqual(ResultT))
4212-
continue;
4213-
4214-
switch (req.getKind()) {
4215-
case RequirementKind::Conformance:
4216-
case RequirementKind::Superclass:
4217-
opaqueTypes.push_back(req.getSecondType());
4218-
break;
4219-
case RequirementKind::Layout:
4220-
hasExplicitAnyObject |= req.getLayoutConstraint()->isClass();
4221-
break;
4222-
case RequirementKind::SameType:
4223-
return nullptr;
4224-
}
4225-
}
4213+
if (auto superTy = genericSig->getSuperclassBound(ResultT))
4214+
opaqueTypes.push_back(superTy);
4215+
for (auto proto : genericSig->getConformsTo(ResultT))
4216+
opaqueTypes.push_back(proto->getDeclaredInterfaceType());
4217+
if (auto layout = genericSig->getLayoutConstraint(ResultT))
4218+
hasExplicitAnyObject = layout->isClass();
42264219

42274220
if (!hasExplicitAnyObject) {
42284221
if (opaqueTypes.empty())

test/IDE/complete_opaque_result.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ protocol HasAssocWithConstraintOnProto where Self.AssocWithConstraintOnProto : M
110110
associatedtype AssocWithConstraintOnProto
111111
func returnAssocWithConstraintOnProto() -> AssocWithConstraintOnProto
112112
}
113-
protocol HasAssocWithSameTypeConstraint where Self.AssocWithSameTypeConstraint == MyClass {
114-
associatedtype AssocWithSameTypeConstraint
113+
protocol HasAssocWithSameTypeConstraint where Self.AssocWithSameTypeConstraint == ConcreteMyProtocol {
114+
associatedtype AssocWithSameTypeConstraint : MyProtocol
115115
func returnAssocWithSameTypeConstraint() -> AssocWithSameTypeConstraint
116116
}
117117
protocol HasAssocWithConformanceConstraintGeneric {

0 commit comments

Comments
 (0)