Skip to content

Commit ac00a8c

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

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

include/swift/AST/TypeRepr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class alignas(1 << TypeReprAlignInBits) TypeRepr
125125
}
126126

127127
/// Is this type representation a protocol?
128-
bool isProtocol(DeclContext *dc);
128+
bool isProtocolOrProtocolComposition(DeclContext *dc);
129129

130130
/// Is this type representation known to be invalid?
131131
bool isInvalid() const { return Bits.TypeRepr.Invalid; }
@@ -408,6 +408,7 @@ class GenericIdentTypeRepr final
408408
return {getTrailingObjects<TypeRepr*>(),
409409
Bits.GenericIdentTypeRepr.NumGenericArgs};
410410
}
411+
411412
SourceRange getAngleBrackets() const { return AngleBrackets; }
412413

413414
static bool classof(const TypeRepr *T) {

lib/AST/NameLookup.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,7 +2924,7 @@ static bool declsAreAssociatedTypes(ArrayRef<TypeDecl *> decls) {
29242924
/// Verify there is at least one protocols in the set of declarations.
29252925
static bool declsAreProtocols(ArrayRef<TypeDecl *> decls) {
29262926
if (decls.empty())
2927-
return false;
2927+
return false; // Below, check outer type repr is a protocol, if not bail early
29282928
return llvm::any_of(decls, [&](const TypeDecl *decl) {
29292929
if (auto *alias = dyn_cast<TypeAliasDecl>(decl)) {
29302930
auto ty = alias->getUnderlyingType();
@@ -2933,14 +2933,12 @@ static bool declsAreProtocols(ArrayRef<TypeDecl *> decls) {
29332933
return false;
29342934
}
29352935
return isa<ProtocolDecl>(decl);
2936-
});;;
2936+
});
29372937
}
29382938

2939-
bool TypeRepr::isProtocol(DeclContext *dc){
2939+
bool TypeRepr::isProtocolOrProtocolComposition(DeclContext *dc){
29402940
auto &ctx = dc->getASTContext();
2941-
return findIf([&ctx, dc](TypeRepr *ty) {
2942-
return declsAreProtocols(directReferencesForTypeRepr(ctx.evaluator, ctx, ty, dc));
2943-
});
2941+
return declsAreProtocols(directReferencesForTypeRepr(ctx.evaluator, ctx, this, dc));
29442942
}
29452943

29462944
static GenericParamList *
@@ -2993,15 +2991,19 @@ CollectedOpaqueReprs swift::collectOpaqueReturnTypeReprs(TypeRepr *r, ASTContext
29932991

29942992
if (auto existential = dyn_cast<ExistentialTypeRepr>(repr)) {
29952993
return Action::SkipChildren();
2996-
} else if (auto compositionRepr = dyn_cast<CompositionTypeRepr>(repr)) {
2997-
if (!compositionRepr->isTypeReprAny())
2998-
Reprs.push_back(compositionRepr);
2994+
} else if (auto composition = dyn_cast<CompositionTypeRepr>(repr)) {
2995+
if (!composition->isTypeReprAny())
2996+
Reprs.push_back(composition);
29992997
return Action::SkipChildren();
30002998
} else if (auto generic = dyn_cast<GenericIdentTypeRepr>(repr)) {
2999+
if (generic->isProtocolOrProtocolComposition(dc)){
3000+
Reprs.push_back(generic);
3001+
return Action::SkipChildren();
3002+
}
30013003
return Action::Continue();
3002-
} else if (auto declRefTR = dyn_cast<DeclRefTypeRepr>(repr)) {
3003-
if (declRefTR->isProtocol(dc))
3004-
Reprs.push_back(declRefTR);
3004+
} else if (auto declRef = dyn_cast<DeclRefTypeRepr>(repr)) {
3005+
if (declRef->isProtocolOrProtocolComposition(dc))
3006+
Reprs.push_back(declRef);
30053007
}
30063008
return Action::Continue();
30073009
}

0 commit comments

Comments
 (0)