| author | |
| committer | |
| log | 7d9e3840bb668f2040b30480deadf8c1a4cad4b0 |
| tree | 7d6ecc5f0207eefe0850ac7ee5047519f9fc5980 |
| parent | 01638c250fa270c8cb3b3416ea55e22988cd32a2 |
Prior to this, the compiler would hit an assertion because the
break_inline would not successfully move the compile-time control flow.3 files changed, 23 insertions(+), 6 deletions(-)
src/Sema.zig+22-3| ... | @@ -964,7 +964,14 @@ fn analyzeBodyInner( | ... | @@ -964,7 +964,14 @@ fn analyzeBodyInner( |
| 964 | break sema.zirBreak(block, inst); | 964 | break sema.zirBreak(block, inst); |
| 965 | } | 965 | } |
| 966 | }, | 966 | }, |
| 967 | .break_inline => break inst, | 967 | .break_inline => { |
| 968 | if (block.is_comptime) { | ||
| 969 | break inst; | ||
| 970 | } else { | ||
| 971 | sema.comptime_break_inst = inst; | ||
| 972 | return error.ComptimeBreak; | ||
| 973 | } | ||
| 974 | }, | ||
| 968 | .repeat => { | 975 | .repeat => { |
| 969 | if (block.is_comptime) { | 976 | if (block.is_comptime) { |
| 970 | // Send comptime control flow back to the beginning of this block. | 977 | // Send comptime control flow back to the beginning of this block. |
| ... | @@ -3572,8 +3579,20 @@ fn resolveBlockBody( | ... | @@ -3572,8 +3579,20 @@ fn resolveBlockBody( |
| 3572 | if (child_block.is_comptime) { | 3579 | if (child_block.is_comptime) { |
| 3573 | return sema.resolveBody(child_block, body, body_inst); | 3580 | return sema.resolveBody(child_block, body, body_inst); |
| 3574 | } else { | 3581 | } else { |
| 3575 | _ = try sema.analyzeBody(child_block, body); | 3582 | if (sema.analyzeBodyInner(child_block, body)) |_| { |
| 3576 | return sema.analyzeBlockBody(parent_block, src, child_block, merges); | 3583 | return sema.analyzeBlockBody(parent_block, src, child_block, merges); |
| 3584 | } else |err| switch (err) { | ||
| 3585 | error.ComptimeBreak => { | ||
| 3586 | const break_inst = sema.comptime_break_inst; | ||
| 3587 | const break_data = sema.code.instructions.items(.data)[break_inst].@"break"; | ||
| 3588 | if (break_data.block_inst == body_inst) { | ||
| 3589 | return sema.resolveInst(break_data.operand); | ||
| 3590 | } else { | ||
| 3591 | return error.ComptimeBreak; | ||
| 3592 | } | ||
| 3593 | }, | ||
| 3594 | else => |e| return e, | ||
| 3595 | } | ||
| 3577 | } | 3596 | } |
| 3578 | } | 3597 | } |
| 3579 | 3598 |
src/type.zig+1-1| ... | @@ -2986,7 +2986,7 @@ pub const Type = extern union { | ... | @@ -2986,7 +2986,7 @@ pub const Type = extern union { |
| 2986 | 2986 | ||
| 2987 | pub fn containerLayout(ty: Type) std.builtin.TypeInfo.ContainerLayout { | 2987 | pub fn containerLayout(ty: Type) std.builtin.TypeInfo.ContainerLayout { |
| 2988 | return switch (ty.tag()) { | 2988 | return switch (ty.tag()) { |
| 2989 | .tuple => .Auto, | 2989 | .tuple, .empty_struct_literal => .Auto, |
| 2990 | .@"struct" => ty.castTag(.@"struct").?.data.layout, | 2990 | .@"struct" => ty.castTag(.@"struct").?.data.layout, |
| 2991 | .@"union" => ty.castTag(.@"union").?.data.layout, | 2991 | .@"union" => ty.castTag(.@"union").?.data.layout, |
| 2992 | .union_tagged => ty.castTag(.union_tagged).?.data.layout, | 2992 | .union_tagged => ty.castTag(.union_tagged).?.data.layout, |
test/behavior/eval.zig-2| ... | @@ -763,8 +763,6 @@ fn scalar(x: u32) u32 { | ... | @@ -763,8 +763,6 @@ fn scalar(x: u32) u32 { |
| 763 | } | 763 | } |
| 764 | 764 | ||
| 765 | test "comptime assign int to optional int" { | 765 | test "comptime assign int to optional int" { |
| 766 | if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO | ||
| 767 | |||
| 768 | comptime { | 766 | comptime { |
| 769 | var x: ?i32 = null; | 767 | var x: ?i32 = null; |
| 770 | x = 2; | 768 | x = 2; |