Skip to content

Commit 0eb072c

Browse files
authored
Merge pull request swiftlang#63542 from angela-laar/fix-type-alias-implicit-some
[NameLookup] Type Aliases should resolve as opaque
2 parents 447e524 + 26c62b1 commit 0eb072c

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
@@ -2873,7 +2873,15 @@ static bool declsAreAssociatedTypes(ArrayRef<TypeDecl *> decls) {
28732873
static bool declsAreProtocols(ArrayRef<TypeDecl *> decls) {
28742874
if (decls.empty())
28752875
return false;
2876-
return llvm::any_of(decls, [&](const TypeDecl *decl) { return isa<ProtocolDecl>(decl); });;;
2876+
return llvm::any_of(decls, [&](const TypeDecl *decl) {
2877+
if (auto *alias = dyn_cast<TypeAliasDecl>(decl)) {
2878+
auto ty = alias->getUnderlyingType();
2879+
decl = ty->getNominalOrBoundGenericNominal();
2880+
if (decl == nullptr || ty->is<ExistentialType>())
2881+
return false;
2882+
}
2883+
return isa<ProtocolDecl>(decl);
2884+
});;;
28772885
}
28782886

28792887
bool TypeRepr::isProtocol(DeclContext *dc){
@@ -2883,7 +2891,6 @@ bool TypeRepr::isProtocol(DeclContext *dc){
28832891
});
28842892
}
28852893

2886-
28872894
static GenericParamList *
28882895
createExtensionGenericParams(ASTContext &ctx,
28892896
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)