Skip to content

Commit 551e3aa

Browse files
authored
Merge pull request #22960 from xedin/rdar-48443263
[CSSimplify] Tuple splat should account for single dependent member p…
2 parents ff662fd + 502e88d commit 551e3aa

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,11 +1085,11 @@ static bool isSingleTupleParam(ASTContext &ctx,
10851085
if (!ctx.isSwiftVersionAtLeast(5))
10861086
paramType = paramType->lookThroughAllOptionalTypes();
10871087

1088-
// Parameter should have a label and be either a tuple tuple type,
1089-
// or a type variable which might later be assigned a tuple type,
1090-
// e.g. opened generic parameter.
1088+
// Parameter should not have a label and be either a tuple,
1089+
// type variable or a dependent member, which might later be
1090+
// assigned (or resolved to) a tuple type, e.g. opened generic parameter.
10911091
return !param.hasLabel() &&
1092-
(paramType->is<TupleType>() || paramType->is<TypeVariableType>());
1092+
(paramType->is<TupleType>() || paramType->isTypeVariableOrMember());
10931093
}
10941094

10951095
/// Attempt to fix missing arguments by introducing type variables

test/Constraints/closures.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,8 +894,12 @@ do {
894894
}
895895

896896
func foo(_ arr: [Int]) {
897+
// FIXME: This behavior related to tuple splat being allowed
898+
// in conversion between a single dependent member
899+
// parameter and empty parameter functions e.g.
900+
// () -> Void `convertable to` (T.V) -> Void.
897901
_ = S(arr, id: \.self_) {
898-
// expected-error@-1 {{contextual type for closure argument list expects 1 argument, which cannot be implicitly ignored}} {{30-30=_ in }}
902+
// expected-error@-1 {{type '_' has no member 'self_'}}
899903
return 42
900904
}
901905
}

test/Constraints/tuple_arguments.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1691,4 +1691,27 @@ _ = x.map { (_: Void) in return () }
16911691
do {
16921692
func f(_: Int...) {}
16931693
let _ = [(1, 2, 3)].map(f) // expected-error {{cannot invoke 'map' with an argument list of type '((Int...) -> ())'}}
1694-
}
1694+
}
1695+
1696+
// rdar://problem/48443263 - cannot convert value of type '() -> Void' to expected argument type '(_) -> Void'
1697+
1698+
protocol P_48443263 {
1699+
associatedtype V
1700+
}
1701+
1702+
func rdar48443263() {
1703+
func foo<T : P_48443263>(_: T, _: (T.V) -> Void) {}
1704+
1705+
struct S1 : P_48443263 {
1706+
typealias V = Void
1707+
}
1708+
1709+
struct S2: P_48443263 {
1710+
typealias V = Int
1711+
}
1712+
1713+
func bar(_ s1: S1, _ s2: S2, _ fn: () -> Void) {
1714+
foo(s1, fn) // Ok because s.V is Void
1715+
foo(s2, fn) // expected-error {{cannot convert value of type '() -> Void' to expected argument type '(_) -> Void'}}
1716+
}
1717+
}

0 commit comments

Comments
 (0)