Skip to content

Commit 41392db

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

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

include/swift/AST/TypeRepr.h

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

411418
static bool classof(const TypeRepr *T) {

lib/AST/NameLookup.cpp

Lines changed: 11 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,19 @@ 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->isProtocol(dc))
2855+
Reprs.push_back(generic);
2856+
if (generic->argsAreProtocols(dc))
2857+
return Action::Continue();
2858+
return Action::SkipChildren();
2859+
} else if (auto declRef = dyn_cast<DeclRefTypeRepr>(repr)) {
2860+
if (declRef->isProtocol(dc))
2861+
Reprs.push_back(declRef);
28592862
}
28602863
return Action::Continue();
28612864
}

0 commit comments

Comments
 (0)