Skip to content

Commit efcd422

Browse files
committed
[NameLookup] Collect implicit opaque GenericParams
Plain protocols with generic type paramters should be collected as opaque types
1 parent 6be15e2 commit efcd422

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

include/swift/AST/TypeRepr.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,12 @@ class GenericIdentTypeRepr final
406406
return {getTrailingObjects<TypeRepr*>(),
407407
Bits.GenericIdentTypeRepr.NumGenericArgs};
408408
}
409+
410+
bool argsAreProtocols(DeclContext *dc) {
411+
auto &ctx = dc->getASTContext();
412+
return llvm::any_of(getGenericArgs(), [&](TypeRepr *genericArg) { return genericArg->isProtocol(dc); });;;
413+
}
414+
409415
SourceRange getAngleBrackets() const { return AngleBrackets; }
410416

411417
static bool classof(const TypeRepr *T) {

lib/AST/NameLookup.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,7 +2801,6 @@ bool TypeRepr::isProtocol(DeclContext *dc){
28012801
});
28022802
}
28032803

2804-
28052804
static GenericParamList *
28062805
createExtensionGenericParams(ASTContext &ctx,
28072806
ExtensionDecl *ext,
@@ -2847,15 +2846,18 @@ CollectedOpaqueReprs swift::collectOpaqueReturnTypeReprs(TypeRepr *r, ASTContext
28472846

28482847
if (auto existential = dyn_cast<ExistentialTypeRepr>(repr)) {
28492848
return Action::SkipChildren();
2850-
} else if (auto compositionRepr = dyn_cast<CompositionTypeRepr>(repr)) {
2851-
if (!compositionRepr->isTypeReprAny())
2852-
Reprs.push_back(compositionRepr);
2849+
} else if (auto composition = dyn_cast<CompositionTypeRepr>(repr)) {
2850+
if (!composition->isTypeReprAny())
2851+
Reprs.push_back(composition);
28532852
return Action::SkipChildren();
28542853
} else if (auto generic = dyn_cast<GenericIdentTypeRepr>(repr)) {
2855-
return Action::Continue();
2856-
} else if (auto declRefTR = dyn_cast<DeclRefTypeRepr>(repr)) {
2857-
if (declRefTR->isProtocol(dc))
2858-
Reprs.push_back(declRefTR);
2854+
if (generic->argsAreProtocols(dc))
2855+
return Action::Continue();
2856+
Reprs.push_back(generic);
2857+
return Action::SkipChildren();
2858+
} else if (auto declRef = dyn_cast<DeclRefTypeRepr>(repr)) {
2859+
if (declRef->isProtocol(dc))
2860+
Reprs.push_back(declRef);
28592861
}
28602862
return Action::Continue();
28612863
}

0 commit comments

Comments
 (0)