@@ -1123,6 +1123,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
1123
1123
auto exprToCheck = yieldExprs[i];
1124
1124
1125
1125
InOutExpr *inout = nullptr ;
1126
+ UnsafeExpr *unsafeExpr = nullptr ;
1126
1127
1127
1128
// Classify whether we're yielding by reference or by value.
1128
1129
ContextualTypePurpose contextTypePurpose;
@@ -1131,6 +1132,11 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
1131
1132
contextTypePurpose = CTP_YieldByReference;
1132
1133
contextType = LValueType::get (contextType);
1133
1134
1135
+ // If present, remove an enclosing 'unsafe' expression.
1136
+ unsafeExpr = dyn_cast<UnsafeExpr>(exprToCheck);
1137
+ if (unsafeExpr)
1138
+ exprToCheck = unsafeExpr->getSubExpr ();
1139
+
1134
1140
// Check that the yielded expression is a &.
1135
1141
if ((inout = dyn_cast<InOutExpr>(exprToCheck))) {
1136
1142
// Strip the & off so that the constraint system doesn't complain
@@ -1158,6 +1164,13 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
1158
1164
exprToCheck = inout;
1159
1165
}
1160
1166
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
+
1161
1174
// Note that this modifies the statement's expression list in-place.
1162
1175
yieldExprs[i] = exprToCheck;
1163
1176
}
0 commit comments