mirror of
https://github.com/ziglang/zig.git
synced 2024-11-28 08:02:32 +00:00
don't crash when can't evaluate comptime expression with inferred type
Closes #15911.
This commit is contained in:
parent
32e719e070
commit
cd1417dbdf
@ -6021,6 +6021,10 @@ pub fn errNoteNonLazy(
|
||||
comptime format: []const u8,
|
||||
args: anytype,
|
||||
) error{OutOfMemory}!void {
|
||||
if (src_loc.lazy == .unneeded) {
|
||||
assert(parent.src_loc.lazy == .unneeded);
|
||||
return;
|
||||
}
|
||||
const msg = try std.fmt.allocPrint(mod.gpa, format, args);
|
||||
errdefer mod.gpa.free(msg);
|
||||
|
||||
|
@ -882,7 +882,7 @@ fn analyzeBodyInner(
|
||||
|
||||
var dbg_block_begins: u32 = 0;
|
||||
|
||||
// We use a while(true) loop here to avoid a redundant way of breaking out of
|
||||
// We use a while (true) loop here to avoid a redundant way of breaking out of
|
||||
// the loop. The only way to break out of the loop is with a `noreturn`
|
||||
// instruction.
|
||||
var i: usize = 0;
|
||||
@ -18073,7 +18073,7 @@ fn zirStructInitAnon(
|
||||
return sema.addConstantMaybeRef(block, tuple_ty, tuple_val, is_ref);
|
||||
};
|
||||
|
||||
sema.requireRuntimeBlock(block, src, .unneeded) catch |err| switch (err) {
|
||||
sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {
|
||||
error.NeededSourceLocation => {
|
||||
const decl = sema.mod.declPtr(block.src_decl);
|
||||
const field_src = Module.initSrc(src.node_offset.x, sema.gpa, decl, runtime_index);
|
||||
@ -18179,7 +18179,7 @@ fn zirArrayInit(
|
||||
return sema.addConstantMaybeRef(block, array_ty, array_val, is_ref);
|
||||
};
|
||||
|
||||
sema.requireRuntimeBlock(block, src, .unneeded) catch |err| switch (err) {
|
||||
sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {
|
||||
error.NeededSourceLocation => {
|
||||
const decl = sema.mod.declPtr(block.src_decl);
|
||||
const elem_src = Module.initSrc(src.node_offset.x, sema.gpa, decl, runtime_index);
|
||||
|
@ -0,0 +1,17 @@
|
||||
const A = struct {
|
||||
a: u8,
|
||||
};
|
||||
|
||||
var n: u8 = 5;
|
||||
var a: A = .{ .a = n };
|
||||
|
||||
pub export fn entry() void {
|
||||
_ = a;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :6:13: error: unable to evaluate comptime expression
|
||||
// :6:16: note: operation is runtime due to this operand
|
Loading…
Reference in New Issue
Block a user