Skip to content

Commit ac11c53

Browse files
authored
Merge pull request #9023 from DougGregor/solver-lvalue-optional-4.0
2 parents 920e4bb + 29ad0d1 commit ac11c53

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,8 @@ static PotentialBindings getPotentialBindings(ConstraintSystem &cs,
11821182
// produce an optional of that type as a potential binding. We
11831183
// overwrite the binding in place because the non-optional type
11841184
// will fail to type-check against the nil-literal conformance.
1185-
auto nominalBindingDecl = binding.BindingType->getAnyNominal();
1185+
auto nominalBindingDecl =
1186+
binding.BindingType->getRValueType()->getAnyNominal();
11861187
bool conformsToExprByNilLiteral = false;
11871188
if (nominalBindingDecl) {
11881189
SmallVector<ProtocolConformance *, 2> conformances;

test/Constraints/optional.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,17 @@ class C2 {
245245
return p1 ?? p2?.prop
246246
}
247247
}
248+
249+
250+
// rdar://problem/31779785
251+
class X { }
252+
253+
class Bar {
254+
let xOpt: X?
255+
let b: Bool
256+
257+
init() {
258+
let result = b ? nil : xOpt
259+
let _: Int = result // expected-error{{cannot convert value of type 'X?' to specified type 'Int'}}
260+
}
261+
}

0 commit comments

Comments
 (0)