Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sema: Fix ConstraintSystem::getTypeOfMemberReference() for protocol typealiases #18465

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@ ConstraintSystem::getTypeOfMemberReference(
// protocols.
if (auto *alias = dyn_cast<TypeAliasDecl>(value)) {
if (baseObjTy->isExistentialType()) {
auto memberTy = alias->getDeclaredInterfaceType();
auto memberTy = alias->getInterfaceType();
// If we end up with a protocol typealias here, it's underlying
// type must be fully concrete.
assert(!memberTy->hasTypeParameter());
Expand Down
2 changes: 1 addition & 1 deletion test/Sema/typo_correction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protocol P { // expected-note {{'P' previously declared here}}
protocol P {} // expected-error {{invalid redeclaration of 'P'}}

func hasTypo() {
_ = P.a.a // expected-error {{value of type 'Generic' has no member 'a'}}
_ = P.a.a // expected-error {{type 'Generic' has no member 'a'}}
}

// Typo correction with AnyObject.
Expand Down
16 changes: 16 additions & 0 deletions test/decl/typealias/protocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,19 @@ struct SomeConformingType : UnboundGenericAliasProto {
protocol UnboundGenericAliasProto {
typealias G = X
}

// If pre-checking cannot resolve a member type due to ambiguity,
// we go down the usual member access path. Make sure its correct
// for protocol typealiases.
protocol Amb1 {
typealias T = Int
}

protocol Amb2 {
typealias T = String
}

typealias Amb = Amb1 & Amb2

let _: Int.Type = Amb.T.self
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AnthonyLatsis Note that this case should always be accepted -- I'm disambiguating the return type of the member access. However, I'm surprised that without the type constraint, Amb.T just picks a random result from the overload set. Maybe @xedin has ideas.

let _: String.Type = Amb.T.self