| ... | ... | @@ -1182,6 +1182,42 @@ test "suspend in for loop" { |
| 1182 | 1182 | S.doTheTest(); |
| 1183 | 1183 | } |
| 1184 | 1184 | |
| 1185 | test "suspend in while loop" { |
| 1186 | const S = struct { |
| 1187 | var global_frame: ?anyframe = null; |
| 1188 | |
| 1189 | fn doTheTest() void { |
| 1190 | _ = async atest(); |
| 1191 | while (global_frame) |f| resume f; |
| 1192 | } |
| 1193 | |
| 1194 | fn atest() void { |
| 1195 | expect(optional(6) == 6); |
| 1196 | expect(errunion(6) == 6); |
| 1197 | } |
| 1198 | fn optional(stuff: ?u32) u32 { |
| 1199 | global_frame = @frame(); |
| 1200 | defer global_frame = null; |
| 1201 | while (stuff) |val| { |
| 1202 | suspend; |
| 1203 | return val; |
| 1204 | } |
| 1205 | return 0; |
| 1206 | } |
| 1207 | fn errunion(stuff: anyerror!u32) u32 { |
| 1208 | global_frame = @frame(); |
| 1209 | defer global_frame = null; |
| 1210 | while (stuff) |val| { |
| 1211 | suspend; |
| 1212 | return val; |
| 1213 | } else |err| { |
| 1214 | return 0; |
| 1215 | } |
| 1216 | } |
| 1217 | }; |
| 1218 | S.doTheTest(); |
| 1219 | } |
| 1220 | |
| 1185 | 1221 | test "correctly spill when returning the error union result of another async fn" { |
| 1186 | 1222 | const S = struct { |
| 1187 | 1223 | var global_frame: anyframe = undefined; |