@@ -4411,6 +4411,13 @@ LValue SILGenLValue::visitBindOptionalExpr(BindOptionalExpr *e,
4411
4411
4412
4412
if (optBase.getType ().isMoveOnly ()) {
4413
4413
if (optBase.getType ().isAddress ()) {
4414
+ // Strip the move-only wrapper if any.
4415
+ if (optBase.getType ().isMoveOnlyWrapped ()) {
4416
+ optBase = ManagedValue::forBorrowedAddressRValue (
4417
+ SGF.B .createMoveOnlyWrapperToCopyableAddr (e,
4418
+ optBase.getValue ()));
4419
+ }
4420
+
4414
4421
optBase = enterAccessScope (SGF, e, ManagedValue (),
4415
4422
optBase, optTypeData,
4416
4423
baseAccessKind,
@@ -4423,13 +4430,26 @@ LValue SILGenLValue::visitBindOptionalExpr(BindOptionalExpr *e,
4423
4430
} else {
4424
4431
optBase = SGF.B .createFormalAccessBeginBorrow (e, optBase, IsNotLexical,
4425
4432
BeginBorrowInst::IsFixed);
4433
+ // Strip the move-only wrapper if any.
4434
+ if (optBase.getType ().isMoveOnlyWrapped ()) {
4435
+ optBase
4436
+ = SGF.B .createGuaranteedMoveOnlyWrapperToCopyableValue (e, optBase);
4437
+ }
4426
4438
}
4427
4439
}
4428
4440
} else {
4429
4441
optBase = SGF.emitAddressOfLValue (e, std::move (optLV));
4442
+ bool isMoveOnly = optBase.getType ().isMoveOnly ();
4443
+
4444
+ // Strip the move-only wrapper if any.
4445
+ if (optBase.getType ().isMoveOnlyWrapped ()) {
4446
+ optBase = ManagedValue::forLValue (
4447
+ SGF.B .createMoveOnlyWrapperToCopyableAddr (e,
4448
+ optBase.getValue ()));
4449
+ }
4430
4450
4431
4451
if (isConsumeAccess (baseAccessKind)) {
4432
- if (optBase. getType (). isMoveOnly () ) {
4452
+ if (isMoveOnly) {
4433
4453
optBase = enterAccessScope (SGF, e, ManagedValue (),
4434
4454
optBase, optTypeData,
4435
4455
baseAccessKind,
0 commit comments