@@ -4411,6 +4411,13 @@ LValue SILGenLValue::visitBindOptionalExpr(BindOptionalExpr *e,
44114411
44124412 if (optBase.getType ().isMoveOnly ()) {
44134413 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+
44144421 optBase = enterAccessScope (SGF, e, ManagedValue (),
44154422 optBase, optTypeData,
44164423 baseAccessKind,
@@ -4423,13 +4430,26 @@ LValue SILGenLValue::visitBindOptionalExpr(BindOptionalExpr *e,
44234430 } else {
44244431 optBase = SGF.B .createFormalAccessBeginBorrow (e, optBase, IsNotLexical,
44254432 BeginBorrowInst::IsFixed);
4433+ // Strip the move-only wrapper if any.
4434+ if (optBase.getType ().isMoveOnlyWrapped ()) {
4435+ optBase
4436+ = SGF.B .createGuaranteedMoveOnlyWrapperToCopyableValue (e, optBase);
4437+ }
44264438 }
44274439 }
44284440 } else {
44294441 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+ }
44304450
44314451 if (isConsumeAccess (baseAccessKind)) {
4432- if (optBase. getType (). isMoveOnly () ) {
4452+ if (isMoveOnly) {
44334453 optBase = enterAccessScope (SGF, e, ManagedValue (),
44344454 optBase, optTypeData,
44354455 baseAccessKind,
0 commit comments