add test case for defer modifying return value before returned

See #961
This commit is contained in:
Andrew Kelley 2019-06-26 23:25:53 -04:00
parent 01ff0d4d62
commit 6c195ede54
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9

View File

@ -76,3 +76,20 @@ fn testNestedFnErrDefer() anyerror!void {
};
return S.baz();
}
test "return variable while defer expression in scope to modify it" {
const S = struct {
fn doTheTest() void {
expect(notNull().? == 1);
}
fn notNull() ?u8 {
var res: ?u8 = 1;
defer res = null;
return res;
}
};
S.doTheTest();
comptime S.doTheTest();
}