Skip to content

Commit 9148b14

Browse files
authored
Merge pull request #14627 from xedin/rdar-37508855-4.1
[4.1][CSBindings] Form bindings correctly when they come from 'OptionalObject' constraint
2 parents 0ededb6 + 13cb3bd commit 9148b14

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,15 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) {
402402
if (type->hasError())
403403
continue;
404404

405+
// If the source of the binding is 'OptionalObject' constraint
406+
// and type variable is on the left-hand side, that means
407+
// that it _has_ to be of optional type, since the right-hand
408+
// side of the constraint is object type of the optional.
409+
if (constraint->getKind() == ConstraintKind::OptionalObject &&
410+
kind == AllowedBindingKind::Subtypes) {
411+
type = OptionalType::get(type);
412+
}
413+
405414
// If the type we'd be binding to is a dependent member, don't try to
406415
// resolve this type variable yet.
407416
if (type->is<DependentMemberType>()) {

test/Constraints/diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ func rdar17170728() {
10971097

10981098
let _ = [i, j, k].reduce(0 as Int?) {
10991099
$0 && $1 ? $0! + $1! : ($0 ? $0! : ($1 ? $1! : nil))
1100-
// expected-error@-1 {{type of expression is ambiguous without more context}}
1100+
// expected-error@-1 {{ambiguous use of operator '+'}}
11011101
}
11021102
}
11031103

test/Constraints/optional.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,8 @@ func testInOutOptionality() {
283283

284284
overloadedByOptionality(&o)
285285
}
286+
287+
// rdar://problem/37508855
288+
func rdar37508855(_ e1: X?, _ e2: X?) -> [X] {
289+
return [e1, e2].filter { $0 == nil }.map { $0! }
290+
}

0 commit comments

Comments
 (0)