Skip to content

Commit 6898fbb

Browse files
committed
[ConstraintSystem] Don't assume the lhs type is for a
generic parameter in simplifyConformsToConstraint.
1 parent 6b01603 commit 6898fbb

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5136,11 +5136,12 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
51365136
// collection type couldn't be determined without unification to
51375137
// `Any` and `+` failing for all numeric overloads is just a consequence.
51385138
if (typeVar && type->isAny()) {
5139-
auto *GP = typeVar->getImpl().getGenericParameter();
5140-
if (auto *GPD = GP->getDecl()) {
5141-
auto *DC = GPD->getDeclContext();
5142-
if (DC->isTypeContext() && DC->getSelfInterfaceType()->isEqual(GP))
5143-
return SolutionKind::Error;
5139+
if (auto *GP = typeVar->getImpl().getGenericParameter()) {
5140+
if (auto *GPD = GP->getDecl()) {
5141+
auto *DC = GPD->getDeclContext();
5142+
if (DC->isTypeContext() && DC->getSelfInterfaceType()->isEqual(GP))
5143+
return SolutionKind::Error;
5144+
}
51445145
}
51455146
}
51465147

test/Constraints/optional.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,3 +420,10 @@ func test_force_unwrap_not_being_too_eager() {
420420
if let _ = obj.delegate?.window { // Ok
421421
}
422422
}
423+
424+
// rdar://problem/57097401
425+
func invalidOptionalChaining(a: Any) {
426+
a == "="? // expected-error {{cannot use optional chaining on non-optional value of type 'String'}}
427+
// expected-error@-1 {{value of protocol type 'Any' cannot conform to 'Equatable'; only struct/enum/class types can conform to protocols}}
428+
// expected-note@-2 {{requirement from conditional conformance of 'Any?' to 'Equatable'}}
429+
}

0 commit comments

Comments
 (0)