Skip to content

Commit 349c005

Browse files
committed
[CSSimplify] Relax isBindable requirements for pack expansion variables
If type variable we are about to bind represents a pack expansion type, allow the binding to happen regardless of what the \c type is, because contextual type is just a hint in this situation and type variable would be bound to its opened type instead. Resolves: rdar://112617922 (cherry picked from commit 27413f5)
1 parent 35fdbd0 commit 349c005

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4194,7 +4194,16 @@ static void enumerateOptionalConversionRestrictions(
41944194
/// Determine whether we can bind the given type variable to the given
41954195
/// fixed type.
41964196
static bool isBindable(TypeVariableType *typeVar, Type type) {
4197-
return !ConstraintSystem::typeVarOccursInType(typeVar, type) &&
4197+
// Disallow recursive bindings.
4198+
if (ConstraintSystem::typeVarOccursInType(typeVar, type))
4199+
return false;
4200+
4201+
// If type variable we are about to bind represents a pack
4202+
// expansion type, allow the binding to happen regardless of
4203+
// what the \c type is, because contextual type is just a hint
4204+
// in this situation and type variable would be bound to its
4205+
// opened type instead.
4206+
return typeVar->getImpl().isPackExpansion() ||
41984207
!type->is<DependentMemberType>();
41994208
}
42004209

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: not %target-swift-frontend %s -typecheck
2+
3+
enum MyError: Error {
4+
case unknown
5+
}
6+
7+
extension Result {
8+
init<each S>(success: repeat each S, failure: Failure?) where Success == (repeat each S.Wrapped), Failure == any Error, repeat each S: OptionalProtocol {
9+
}
10+
}
11+
12+
protocol OptionalProtocol {
13+
associatedtype Wrapped
14+
var asOptional: Optional<Wrapped> { get }
15+
}
16+
17+
extension Optional: OptionalProtocol {
18+
var asOptional: Optional<Wrapped> { self }
19+
}
20+
21+
func test<each EncodedResult: OptionalProtocol>(
22+
_ transformed: @escaping (Result<(repeat each EncodedResult.Wrapped), any Error>) -> Void
23+
) -> ((any Error)?, repeat each EncodedResult) -> Void where repeat each EncodedResult.Wrapped: DataProtocol {
24+
return {
25+
transformed(Result(success: $1, failure: $0))
26+
}
27+
}

0 commit comments

Comments
 (0)