| author | |
| committer | |
| log | 18770721ac919abd8d4dc6d117a6798a462106be |
| tree | 9b4e84d2ead256884a6fe9b839127f494973fa0f |
| parent | 7b8a968f14a8405c209f35d8a0f904d6f722e713 |
2 files changed, 8 insertions(+), 0 deletions(-)
src/AstGen.zig+4| ... | @@ -6167,6 +6167,10 @@ fn ret(gz: *GenZir, scope: *Scope, node: ast.Node.Index) InnerError!Zir.Inst.Ref | ... | @@ -6167,6 +6167,10 @@ fn ret(gz: *GenZir, scope: *Scope, node: ast.Node.Index) InnerError!Zir.Inst.Ref |
| 6167 | const node_datas = tree.nodes.items(.data); | 6167 | const node_datas = tree.nodes.items(.data); |
| 6168 | const node_tags = tree.nodes.items(.tag); | 6168 | const node_tags = tree.nodes.items(.tag); |
| 6169 | 6169 | ||
| 6170 | if (astgen.fn_block == null) { | ||
| 6171 | return astgen.failNode(node, "'return' outside function scope", .{}); | ||
| 6172 | } | ||
| 6173 | |||
| 6170 | if (gz.in_defer) return astgen.failNode(node, "cannot return from defer expression", .{}); | 6174 | if (gz.in_defer) return astgen.failNode(node, "cannot return from defer expression", .{}); |
| 6171 | 6175 | ||
| 6172 | const defer_outer = &astgen.fn_block.?.base; | 6176 | const defer_outer = &astgen.fn_block.?.base; |
test/compile_errors.zig+4| ... | @@ -2,6 +2,10 @@ const std = @import("std"); | ... | @@ -2,6 +2,10 @@ const std = @import("std"); |
| 2 | const TestContext = @import("../src/test.zig").TestContext; | 2 | const TestContext = @import("../src/test.zig").TestContext; |
| 3 | 3 | ||
| 4 | pub fn addCases(ctx: *TestContext) !void { | 4 | pub fn addCases(ctx: *TestContext) !void { |
| 5 | ctx.objErrStage1("issue #9346: return outside of function scope", | ||
| 6 | \\pub const empty = return 1; | ||
| 7 | , &.{"tmp.zig:1:19: error: 'return' outside function scope"}); | ||
| 8 | |||
| 5 | ctx.exeErrStage1("std.fmt error for unused arguments", | 9 | ctx.exeErrStage1("std.fmt error for unused arguments", |
| 6 | \\pub fn main() !void { | 10 | \\pub fn main() !void { |
| 7 | \\ @import("std").debug.print("{d} {d} {d} {d} {d}", .{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}); | 11 | \\ @import("std").debug.print("{d} {d} {d} {d} {d}", .{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}); |