Skip to content

Commit b1930a8

Browse files
authored
Merge pull request #60080 from xedin/rdar-88513939
[CSSimplify] Allow referencing typealias declarations via leading-dot…
2 parents 1685e92 + 1277618 commit b1930a8

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7357,6 +7357,12 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
73577357
}
73587358
}
73597359

7360+
if (loc->isLastElement<LocatorPathElt::MemberRefBase>()) {
7361+
auto *fix = ContextualMismatch::create(*this, protocolTy, type, loc);
7362+
if (!recordFix(fix))
7363+
return SolutionKind::Solved;
7364+
}
7365+
73607366
// If this is an implicit Hashable conformance check generated for each
73617367
// index argument of the keypath subscript component, we could just treat
73627368
// it as though it conforms.
@@ -9751,7 +9757,7 @@ ConstraintSystem::simplifyUnresolvedMemberChainBaseConstraint(
97519757
return SolutionKind::Solved;
97529758

97539759
auto *memberRef = findResolvedMemberRef(memberLoc);
9754-
if (memberRef && memberRef->isStatic()) {
9760+
if (memberRef && (memberRef->isStatic() || isa<TypeAliasDecl>(memberRef))) {
97559761
return simplifyConformsToConstraint(
97569762
resultTy, baseTy, ConstraintKind::ConformsTo,
97579763
getConstraintLocator(memberLoc, ConstraintLocator::MemberRefBase),

test/Constraints/static_members_on_protocol_in_generic_context.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,28 @@ func acceptStyle<S: Style>(_: S) {}
325325

326326
acceptStyle(.formattedString(format: "hi")) // Ok
327327
acceptStyle(.number(42)) // Ok
328+
329+
protocol Container {
330+
associatedtype Content
331+
}
332+
333+
struct Box<T>: Container { // expected-note {{'T' declared as parameter to type 'Box'}}
334+
typealias Content = T
335+
init(_: Content) {}
336+
}
337+
338+
extension Container {
339+
// leading-dot syntax is going to use a typealias
340+
typealias box = Box
341+
}
342+
343+
// rdar://88513939 - Allow to call init through a typealias using leading-dot syntax in generic context
344+
func test_leading_dot_syntax_with_typelias() {
345+
func test<T: Container>(_: T) {} // expected-note {{required by local function 'test' where 'T' = 'Box<T>.Type'}}
346+
347+
test(Container.box(1)) // Ok
348+
test(.box(1)) // Ok `Container.box(1)` means `Box.init(1)`
349+
350+
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}}
351+
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
352+
}

0 commit comments

Comments
 (0)