From 561ecd882637b5c76ee077ee250e95f19b78e38d Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 3 Jul 2025 00:18:33 -0400 Subject: [PATCH] Sema: Fix leading dot with protocol composition or parameterized protocol contextual type - Fixes https://github.com/swiftlang/swift/issues/60552. - Fixes rdar://problem/99699879. --- lib/Sema/CSApply.cpp | 2 +- test/Constraints/issue-60552.swift | 31 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/Constraints/issue-60552.swift diff --git a/lib/Sema/CSApply.cpp b/lib/Sema/CSApply.cpp index a7e4fed2038..077785c16b6 100644 --- a/lib/Sema/CSApply.cpp +++ b/lib/Sema/CSApply.cpp @@ -1679,7 +1679,7 @@ namespace { // \endcode // // Here `P.foo` would be replaced with `S.foo` - if (!isExistentialMetatype && baseTy->is() && + if (!isExistentialMetatype && baseTy->isConstraintType() && member->isStatic()) { auto selfParam = overload.adjustedOpenedFullType->castTo()->getParams()[0]; diff --git a/test/Constraints/issue-60552.swift b/test/Constraints/issue-60552.swift new file mode 100644 index 00000000000..683dcfd55bb --- /dev/null +++ b/test/Constraints/issue-60552.swift @@ -0,0 +1,31 @@ +// RUN: %target-swift-emit-silgen %s + +// rdar://150858005 +protocol P {} +protocol Q {} + +struct MyP: P, Q {} + +extension P where Self == MyP { + static var myP: Self { return MyP() } +} + +func test() { + let _: any P & Q = .myP +} + +// rdar://148708774 +protocol Wrapper { + associatedtype Wrapped +} +struct IntWrapper: Wrapper { + typealias Wrapped = Int +} + +extension Wrapper where Self == IntWrapper { + static var int: Self { fatalError() } +} + +let crashes: any Wrapper = .int +let ok1: some Wrapper = .int +let ok2: any Wrapper = .int