Skip to content

Commit 26c62b1

Browse files
committed
[NameLookup] Type Aliases should resolve as opaque
Type aliases for plain protocols should resolve as opaque types with implicit some feature flag Fixes rdar://101403690
1 parent cba7389 commit 26c62b1

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

lib/AST/NameLookup.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2791,7 +2791,15 @@ static bool declsAreAssociatedTypes(ArrayRef<TypeDecl *> decls) {
27912791
static bool declsAreProtocols(ArrayRef<TypeDecl *> decls) {
27922792
if (decls.empty())
27932793
return false;
2794-
return llvm::any_of(decls, [&](const TypeDecl *decl) { return isa<ProtocolDecl>(decl); });;;
2794+
return llvm::any_of(decls, [&](const TypeDecl *decl) {
2795+
if (auto *alias = dyn_cast<TypeAliasDecl>(decl)) {
2796+
auto ty = alias->getUnderlyingType();
2797+
decl = ty->getNominalOrBoundGenericNominal();
2798+
if (decl == nullptr || ty->is<ExistentialType>())
2799+
return false;
2800+
}
2801+
return isa<ProtocolDecl>(decl);
2802+
});;;
27952803
}
27962804

27972805
bool TypeRepr::isProtocol(DeclContext *dc){
@@ -2801,7 +2809,6 @@ bool TypeRepr::isProtocol(DeclContext *dc){
28012809
});
28022810
}
28032811

2804-
28052812
static GenericParamList *
28062813
createExtensionGenericParams(ASTContext &ctx,
28072814
ExtensionDecl *ext,

test/type/implicit_some/explicit_existential.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,6 @@ protocol Output {
208208
associatedtype A
209209
}
210210

211-
212-
213-
// NOT SURE IF THIS WILL WORK
214-
215211
// ImplicitSome feature always expects explicit 'any' and plain protocols now imply 'some'
216212
// Verify existential_requires_any error is no longer produced
217213
typealias OpaqueFunction = (Input) -> Output

test/type/implicit_some/opaque_return.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ func inspect( _ snack: some Snack) -> some Snack {
7373
// tuple type alias
7474
func highestRated() -> (some Snack, some Snack) { } // expected-error {{function declares an opaque return type, but has no return statements in its body from which to infer an underlying type}}
7575

76-
// TO-DO: Fix type alias for plain protocols; resolves as an existential type
77-
func list(_: (Meal, Meal)) -> (Meal, Meal){ }
76+
func list(_: (Meal, Meal)) -> (Meal, Meal){ } // expected-error {{function declares an opaque return type, but has no return statements in its body from which to infer an underlying type}}
77+
7878
func find() -> Snack { }
7979

8080
// opaque compostion types

0 commit comments

Comments
 (0)