| author | |
| committer | |
| log | 7461309b730f4a25f56d71b1a4d6c7dc6b16a39a |
| tree | b63e62593a113af5de2e9665a6c4d953e124e6e9 |
| parent | 80f3ef6e14a1213d1c3b31d515870afb43cc9379 |
Resolves: #189972 files changed, 17 insertions(+), 0 deletions(-)
src/Sema.zig+7| ... | ... | @@ -4149,6 +4149,13 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 4149 | 4149 | return; |
| 4150 | 4150 | } |
| 4151 | 4151 | |
| 4152 | if (try sema.typeRequiresComptime(final_elem_ty)) { | |
| 4153 | // The alloc wasn't comptime-known per the above logic, so the | |
| 4154 | // type cannot be comptime-only. | |
| 4155 | // TODO: source location of runtime control flow | |
| 4156 | return sema.fail(block, src, "value with comptime-only type '{}' depends on runtime control flow", .{final_elem_ty.fmt(mod)}); | |
| 4157 | } | |
| 4158 | ||
| 4152 | 4159 | try sema.queueFullTypeResolution(final_elem_ty); |
| 4153 | 4160 | |
| 4154 | 4161 | // Change it to a normal alloc. |
test/cases/compile_errors/runtime_condition_comptime_type_in_destructure.zig created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | export fn foobar() void { | |
| 2 | var t = true; | |
| 3 | _ = &t; | |
| 4 | const a, _ = if (t) .{ .a, {} } else .{ .b, {} }; | |
| 5 | _ = a; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // | |
| 10 | // :4:5: error: value with comptime-only type '@TypeOf(.enum_literal)' depends on runtime control flow |