mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 07:32:44 +00:00
Sema: validate that runtime-known inferred alloc does not have comptime-only type
Resolves: #18997
This commit is contained in:
parent
80f3ef6e14
commit
7461309b73
@ -4149,6 +4149,13 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
|
||||
return;
|
||||
}
|
||||
|
||||
if (try sema.typeRequiresComptime(final_elem_ty)) {
|
||||
// The alloc wasn't comptime-known per the above logic, so the
|
||||
// type cannot be comptime-only.
|
||||
// TODO: source location of runtime control flow
|
||||
return sema.fail(block, src, "value with comptime-only type '{}' depends on runtime control flow", .{final_elem_ty.fmt(mod)});
|
||||
}
|
||||
|
||||
try sema.queueFullTypeResolution(final_elem_ty);
|
||||
|
||||
// Change it to a normal alloc.
|
||||
|
@ -0,0 +1,10 @@
|
||||
export fn foobar() void {
|
||||
var t = true;
|
||||
_ = &t;
|
||||
const a, _ = if (t) .{ .a, {} } else .{ .b, {} };
|
||||
_ = a;
|
||||
}
|
||||
|
||||
// error
|
||||
//
|
||||
// :4:5: error: value with comptime-only type '@TypeOf(.enum_literal)' depends on runtime control flow
|
Loading…
Reference in New Issue
Block a user