Skip to content

Commit eecca7a

Browse files
committed
[CSSimplify] Allow referencing typealias declarations via leading-dot syntax in generic context
Previously only static methods found on protocols were allowed but it is reasonable to reference a typealias to perform an implicit call to `.init` on its underlying type. Resolves: rdar://88513939
1 parent 9a38146 commit eecca7a

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9727,7 +9727,7 @@ ConstraintSystem::simplifyUnresolvedMemberChainBaseConstraint(
97279727
return SolutionKind::Solved;
97289728

97299729
auto *memberRef = findResolvedMemberRef(memberLoc);
9730-
if (memberRef && memberRef->isStatic()) {
9730+
if (memberRef && (memberRef->isStatic() || isa<TypeAliasDecl>(memberRef))) {
97319731
return simplifyConformsToConstraint(
97329732
resultTy, baseTy, ConstraintKind::ConformsTo,
97339733
getConstraintLocator(memberLoc, ConstraintLocator::MemberRefBase),

test/Constraints/static_members_on_protocol_in_generic_context.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,25 @@ 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 {
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) {}
346+
347+
test(Container.box(1)) // Ok
348+
test(.box(1)) // Ok `Container.box(1)` means `Box.init(1)`
349+
}

0 commit comments

Comments
 (0)