add test case for defer modifying return value before returned
See #961
1 files changed, 17 insertions(+), 0 deletions(-)
test/stage1/behavior/defer.zig+17
| ... | ... | @@ -76,3 +76,20 @@ fn testNestedFnErrDefer() anyerror!void { |
| 76 | 76 | }; |
| 77 | 77 | return S.baz(); |
| 78 | 78 | } |
| 79 | |
| 80 | test "return variable while defer expression in scope to modify it" { |
| 81 | const S = struct { |
| 82 | fn doTheTest() void { |
| 83 | expect(notNull().? == 1); |
| 84 | } |
| 85 | |
| 86 | fn notNull() ?u8 { |
| 87 | var res: ?u8 = 1; |
| 88 | defer res = null; |
| 89 | return res; |
| 90 | } |
| 91 | }; |
| 92 | |
| 93 | S.doTheTest(); |
| 94 | comptime S.doTheTest(); |
| 95 | } |