Skip to content

Commit ef628f2

Browse files
committed
[CodeCompletion] Use GenericSignature methods to get associatedtype reqs
(cherry picked from commit b9f1e58)
1 parent 152e428 commit ef628f2

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
@@ -4238,28 +4238,21 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
42384238
// If resolved print it.
42394239
return nullptr;
42404240

4241-
// Collect requirements on the associatedtype.
4242-
ProtocolDecl *protoD =
4243-
ResultT->castTo<DependentMemberType>()->getAssocType()->getProtocol();
4241+
auto genericSig = VD->getDeclContext()->getGenericSignatureOfContext();
4242+
4243+
if (genericSig->isConcreteType(ResultT))
4244+
// If it has same type requrement, we will emit the concrete type.
4245+
return nullptr;
42444246

4247+
// Collect requirements on the associatedtype.
42454248
SmallVector<Type, 2> opaqueTypes;
42464249
bool hasExplicitAnyObject = false;
4247-
for (auto req : protoD->getRequirementSignature()) {
4248-
if (!req.getFirstType()->isEqual(ResultT))
4249-
continue;
4250-
4251-
switch (req.getKind()) {
4252-
case RequirementKind::Conformance:
4253-
case RequirementKind::Superclass:
4254-
opaqueTypes.push_back(req.getSecondType());
4255-
break;
4256-
case RequirementKind::Layout:
4257-
hasExplicitAnyObject |= req.getLayoutConstraint()->isClass();
4258-
break;
4259-
case RequirementKind::SameType:
4260-
return nullptr;
4261-
}
4262-
}
4250+
if (auto superTy = genericSig->getSuperclassBound(ResultT))
4251+
opaqueTypes.push_back(superTy);
4252+
for (auto proto : genericSig->getConformsTo(ResultT))
4253+
opaqueTypes.push_back(proto->getDeclaredInterfaceType());
4254+
if (auto layout = genericSig->getLayoutConstraint(ResultT))
4255+
hasExplicitAnyObject = layout->isClass();
42634256

42644257
if (!hasExplicitAnyObject) {
42654258
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)