| author | |
| committer | |
| log | 6c195ede54fe9f75c794204fb39c915a9e5581ed |
| tree | 549b048a21cc7818829b55b27ea0af3f267ba40f |
| parent | 01ff0d4d629c3800ebac68edfd91edb570aeaa59 |
| signature |
See #9611 files changed, 17 insertions(+), 0 deletions(-)
test/stage1/behavior/defer.zig+17| ... | @@ -76,3 +76,20 @@ fn testNestedFnErrDefer() anyerror!void { | ... | @@ -76,3 +76,20 @@ fn testNestedFnErrDefer() anyerror!void { |
| 76 | }; | 76 | }; |
| 77 | return S.baz(); | 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 | } |