Skip to content

[CSSimplify] Allow referencing typealias declarations via leading-dot… #60080

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

Merged
merged 1 commit into from
Jul 19, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7333,6 +7333,12 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
}
}

if (loc->isLastElement<LocatorPathElt::MemberRefBase>()) {
auto *fix = ContextualMismatch::create(*this, protocolTy, type, loc);
if (!recordFix(fix))
return SolutionKind::Solved;
}

// If this is an implicit Hashable conformance check generated for each
// index argument of the keypath subscript component, we could just treat
// it as though it conforms.
Expand Down Expand Up @@ -9727,7 +9733,7 @@ ConstraintSystem::simplifyUnresolvedMemberChainBaseConstraint(
return SolutionKind::Solved;

auto *memberRef = findResolvedMemberRef(memberLoc);
if (memberRef && memberRef->isStatic()) {
if (memberRef && (memberRef->isStatic() || isa<TypeAliasDecl>(memberRef))) {
return simplifyConformsToConstraint(
resultTy, baseTy, ConstraintKind::ConformsTo,
getConstraintLocator(memberLoc, ConstraintLocator::MemberRefBase),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,28 @@ func acceptStyle<S: Style>(_: S) {}

acceptStyle(.formattedString(format: "hi")) // Ok
acceptStyle(.number(42)) // Ok

protocol Container {
associatedtype Content
}

struct Box<T>: Container { // expected-note {{'T' declared as parameter to type 'Box'}}
typealias Content = T
init(_: Content) {}
}

extension Container {
// leading-dot syntax is going to use a typealias
typealias box = Box
}

// rdar://88513939 - Allow to call init through a typealias using leading-dot syntax in generic context
func test_leading_dot_syntax_with_typelias() {
func test<T: Container>(_: T) {} // expected-note {{required by local function 'test' where 'T' = 'Box<T>.Type'}}

test(Container.box(1)) // Ok
test(.box(1)) // Ok `Container.box(1)` means `Box.init(1)`

test(.box) // expected-error {{type 'Box<T>.Type' cannot conform to 'Container'}} expected-note {{only concrete types such as structs, enums and classes can conform to protocols}}
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
}