@@ -1123,6 +1123,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
11231123 auto exprToCheck = yieldExprs[i];
11241124
11251125 InOutExpr *inout = nullptr ;
1126+ UnsafeExpr *unsafeExpr = nullptr ;
11261127
11271128 // Classify whether we're yielding by reference or by value.
11281129 ContextualTypePurpose contextTypePurpose;
@@ -1131,6 +1132,11 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
11311132 contextTypePurpose = CTP_YieldByReference;
11321133 contextType = LValueType::get (contextType);
11331134
1135+ // If present, remove an enclosing 'unsafe' expression.
1136+ unsafeExpr = dyn_cast<UnsafeExpr>(exprToCheck);
1137+ if (unsafeExpr)
1138+ exprToCheck = unsafeExpr->getSubExpr ();
1139+
11341140 // Check that the yielded expression is a &.
11351141 if ((inout = dyn_cast<InOutExpr>(exprToCheck))) {
11361142 // Strip the & off so that the constraint system doesn't complain
@@ -1158,6 +1164,13 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
11581164 exprToCheck = inout;
11591165 }
11601166
1167+ // Propagate the change to the unsafe expression we stripped before.
1168+ if (unsafeExpr) {
1169+ unsafeExpr->setSubExpr (exprToCheck);
1170+ unsafeExpr->setType (exprToCheck->getType ());
1171+ exprToCheck = unsafeExpr;
1172+ }
1173+
11611174 // Note that this modifies the statement's expression list in-place.
11621175 yieldExprs[i] = exprToCheck;
11631176 }
0 commit comments