Skip to content

Commit cb73ffb

Browse files
committed
Fix assert with incorrectly allowing optional injection into operator inout argument.
1 parent 1380590 commit cb73ffb

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2293,7 +2293,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
22932293
if (auto *lvt = type1->getAs<LValueType>()) {
22942294
if (auto *iot = type2->getAs<InOutType>()) {
22952295
return matchTypes(lvt->getObjectType(), iot->getObjectType(),
2296-
kind, subflags,
2296+
ConstraintKind::Equal, subflags,
22972297
locator.withPathElement(
22982298
ConstraintLocator::LValueConversion));
22992299
}

test/Constraints/operator.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,10 @@ struct S_37290898: P_37290898 {}
201201
func rdar37290898(_ arr: inout [P_37290898], _ element: S_37290898?) {
202202
arr += [element].compactMap { $0 } // Ok
203203
}
204+
205+
// SR-8221
206+
infix operator ??=
207+
func ??= <T>(lhs: inout T?, rhs: T?) {}
208+
var c: Int = 0
209+
c ??= 5 // expected-error{{binary operator '??=' cannot be applied to two 'Int' operands}}
210+
// expected-note@-1{{expected an argument list of type '(inout T?, T?)'}}

0 commit comments

Comments
 (0)