mirror of
https://github.com/ziglang/zig.git
synced 2025-12-09 15:53:08 +00:00
AstGen: labeled blocks should always complete with a normal break
They aren't inline blocks by nature of being labeled. Fixes #11213
This commit is contained in:
parent
13321c8070
commit
3e74acb139
@ -2018,7 +2018,7 @@ fn labeledBlockExpr(
|
|||||||
|
|
||||||
try blockExprStmts(&block_scope, &block_scope.base, statements);
|
try blockExprStmts(&block_scope, &block_scope.base, statements);
|
||||||
if (!block_scope.endsWithNoReturn()) {
|
if (!block_scope.endsWithNoReturn()) {
|
||||||
_ = try block_scope.addBreak(.break_inline, block_inst, .void_value);
|
_ = try block_scope.addBreak(.@"break", block_inst, .void_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!block_scope.label.?.used) {
|
if (!block_scope.label.?.used) {
|
||||||
|
|||||||
@ -70,6 +70,7 @@ test {
|
|||||||
_ = @import("behavior/bugs/11165.zig");
|
_ = @import("behavior/bugs/11165.zig");
|
||||||
_ = @import("behavior/bugs/11181.zig");
|
_ = @import("behavior/bugs/11181.zig");
|
||||||
_ = @import("behavior/bugs/11182.zig");
|
_ = @import("behavior/bugs/11182.zig");
|
||||||
|
_ = @import("behavior/bugs/11213.zig");
|
||||||
_ = @import("behavior/call.zig");
|
_ = @import("behavior/call.zig");
|
||||||
_ = @import("behavior/cast.zig");
|
_ = @import("behavior/cast.zig");
|
||||||
_ = @import("behavior/comptime_memory.zig");
|
_ = @import("behavior/comptime_memory.zig");
|
||||||
|
|||||||
37
test/behavior/bugs/11213.zig
Normal file
37
test/behavior/bugs/11213.zig
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
const std = @import("std");
|
||||||
|
const builtin = @import("builtin");
|
||||||
|
const testing = std.testing;
|
||||||
|
|
||||||
|
test {
|
||||||
|
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
|
||||||
|
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||||
|
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||||
|
|
||||||
|
const g: error{Test}!void = error.Test;
|
||||||
|
|
||||||
|
var v: u32 = 0;
|
||||||
|
hash(&v, g);
|
||||||
|
try testing.expect(v == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hash(v: *u32, key: anytype) void {
|
||||||
|
const Key = @TypeOf(key);
|
||||||
|
|
||||||
|
if (@typeInfo(Key) == .ErrorSet) {
|
||||||
|
v.* += 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (@typeInfo(Key)) {
|
||||||
|
.ErrorUnion => blk: {
|
||||||
|
const payload = key catch |err| {
|
||||||
|
hash(v, err);
|
||||||
|
break :blk;
|
||||||
|
};
|
||||||
|
|
||||||
|
hash(v, payload);
|
||||||
|
},
|
||||||
|
|
||||||
|
else => unreachable,
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user