Skip to content

Commit 99a644e

Browse files
authored
Merge pull request #60134 from xedin/rdar-88513939-5.7
[5.7][CSSimplify] Allow referencing typealias declarations via leading-dot…
2 parents 8f0d84a + a360d3e commit 99a644e

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
@@ -7421,6 +7421,12 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
74217421
}
74227422
}
74237423

7424+
if (loc->isLastElement<LocatorPathElt::MemberRefBase>()) {
7425+
auto *fix = ContextualMismatch::create(*this, protocolTy, type, loc);
7426+
if (!recordFix(fix))
7427+
return SolutionKind::Solved;
7428+
}
7429+
74247430
// If this is an implicit Hashable conformance check generated for each
74257431
// index argument of the keypath subscript component, we could just treat
74267432
// it as though it conforms.
@@ -9802,7 +9808,7 @@ ConstraintSystem::simplifyUnresolvedMemberChainBaseConstraint(
98029808
return SolutionKind::Solved;
98039809

98049810
auto *memberRef = findResolvedMemberRef(memberLoc);
9805-
if (memberRef && memberRef->isStatic()) {
9811+
if (memberRef && (memberRef->isStatic() || isa<TypeAliasDecl>(memberRef))) {
98069812
return simplifyConformsToConstraint(
98079813
resultTy, baseTy, ConstraintKind::ConformsTo,
98089814
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)