Skip to content

Commit cbfe349

Browse files
committed
Revert "[CSBindings] Delay inference through OptionalObject if "object" is l-value capable"
This reverts commit 700a57a.
1 parent ab230b9 commit cbfe349

File tree

2 files changed

+7
-28
lines changed

2 files changed

+7
-28
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,26 +1646,6 @@ PotentialBindings::inferFromRelational(Constraint *constraint) {
16461646
/// those types should be opened.
16471647
void PotentialBindings::infer(Constraint *constraint) {
16481648
switch (constraint->getKind()) {
1649-
case ConstraintKind::OptionalObject: {
1650-
// Inference through optional object is allowed if
1651-
// one of the types is resolved or "optional" type variable
1652-
// cannot be bound to l-value, otherwise there is a
1653-
// risk of binding "optional" to an optional type (inferred from
1654-
// the "object") and discovering an l-value binding for it later.
1655-
auto optionalType = constraint->getFirstType();
1656-
1657-
if (auto *optionalVar = optionalType->getAs<TypeVariableType>()) {
1658-
if (optionalVar->getImpl().canBindToLValue()) {
1659-
auto objectType =
1660-
constraint->getSecondType()->lookThroughAllOptionalTypes();
1661-
if (objectType->isTypeVariableOrMember())
1662-
return;
1663-
}
1664-
}
1665-
1666-
LLVM_FALLTHROUGH;
1667-
}
1668-
16691649
case ConstraintKind::Bind:
16701650
case ConstraintKind::Equal:
16711651
case ConstraintKind::BindParam:
@@ -1675,6 +1655,7 @@ void PotentialBindings::infer(Constraint *constraint) {
16751655
case ConstraintKind::Conversion:
16761656
case ConstraintKind::ArgumentConversion:
16771657
case ConstraintKind::OperatorArgumentConversion:
1658+
case ConstraintKind::OptionalObject:
16781659
case ConstraintKind::UnresolvedMemberChainBase: {
16791660
auto binding = inferFromRelational(constraint);
16801661
if (!binding)

test/Constraints/diagnostics.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,11 +1121,9 @@ func rdar17170728() {
11211121
var j: Int?
11221122
var k: Int? = 2
11231123

1124-
let _ = [i, j, k].reduce(0 as Int?) { // expected-error {{missing argument label 'into:' in call}}
1125-
// expected-error@-1 {{cannot convert value of type 'Int?' to expected argument type '(inout @escaping (Bool, Bool) -> Bool?, Int?) throws -> ()'}}
1124+
let _ = [i, j, k].reduce(0 as Int?) {
11261125
$0 && $1 ? $0! + $1! : ($0 ? $0! : ($1 ? $1! : nil))
1127-
// expected-error@-1 {{binary operator '+' cannot be applied to two 'Bool' operands}}
1128-
// expected-error@-2 4 {{cannot force unwrap value of non-optional type 'Bool'}}
1126+
// expected-error@-1 4 {{optional type 'Int?' cannot be used as a boolean; test for '!= nil' instead}}
11291127
}
11301128

11311129
let _ = [i, j, k].reduce(0 as Int?) { // expected-error {{missing argument label 'into:' in call}}
@@ -1555,18 +1553,18 @@ func testNilCoalescingOperatorRemoveFix() {
15551553
let _ = "" /* This is a comment */ ?? "" // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{13-43=}}
15561554

15571555
let _ = "" // This is a comment
1558-
?? "" // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1557:13-1558:10=}}
1556+
?? "" // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1555:13-1556:10=}}
15591557

15601558
let _ = "" // This is a comment
15611559
/*
15621560
* The blank line below is part of the test case, do not delete it
15631561
*/
15641562

1565-
?? "" // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1560:13-1565:10=}}
1563+
?? "" // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1558:13-1563:10=}}
15661564

1567-
if ("" ?? // This is a comment // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{9-1568:9=}}
1565+
if ("" ?? // This is a comment // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{9-1566:9=}}
15681566
"").isEmpty {}
15691567

15701568
if ("" // This is a comment
1571-
?? "").isEmpty {} // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1570:9-1571:12=}}
1569+
?? "").isEmpty {} // expected-warning {{left side of nil coalescing operator '??' has non-optional type 'String', so the right side is never used}} {{1568:9-1569:12=}}
15721570
}

0 commit comments

Comments
 (0)