From 1f5a0b4c88833769d7205f575a1542d3a11ba6db Mon Sep 17 00:00:00 2001 From: Hamish Knight Date: Tue, 14 Oct 2025 14:49:37 +0100 Subject: [PATCH] [CS] Use `simplifyType` in `isDependentMemberTypeWithBaseThatContainsUnresolvedPackExpansions` The pack expansion type variable may be a nested in the fixed type of another type variable, and as such we unfortunately need to fully `simplifyType` here. rdar://162545380 --- lib/Sema/CSSimplify.cpp | 7 +++++-- .../pack-expansion-expressions.swift | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index a5ecad0518fa1..4cf84fecad1e8 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -7104,8 +7104,11 @@ static bool isDependentMemberTypeWithBaseThatContainsUnresolvedPackExpansions( if (!type->is()) return false; - auto baseTy = cs.getFixedTypeRecursive(type->getDependentMemberRoot(), - /*wantRValue=*/true); + // FIXME: It's really unfortunate we need to use `simplifyType` here since + // this is called from `matchTypes`. We need to completely simplify the type + // though since pack expansions can be present in fixed types for nested + // type vars. + auto baseTy = cs.simplifyType(type->getDependentMemberRoot()); llvm::SmallPtrSet typeVars; baseTy->getTypeVariables(typeVars); return llvm::any_of(typeVars, [](const TypeVariableType *typeVar) { diff --git a/test/Constraints/pack-expansion-expressions.swift b/test/Constraints/pack-expansion-expressions.swift index aac7b76880256..592740c24b6a3 100644 --- a/test/Constraints/pack-expansion-expressions.swift +++ b/test/Constraints/pack-expansion-expressions.swift @@ -833,3 +833,23 @@ func test_dependent_members() { return Variadic.f(c1, c2) // Ok } } + +protocol P2 { + associatedtype X +} + +extension P2 { + func foo() where X == Bool {} + func foo() where X == String {} +} + +do { + struct S: P2 { + typealias X = String + init(_ fn: () -> (repeat each E)) {} + } + + func foo(_ x: Int) { + S { x }.foo() // Make sure we can pick the right 'foo' here. + } +}