authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-26 13:30:20+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-26 16:40:24+03:00
log3d18c8c1300986541bc81d60e81fd702d4417629
tree95bb478a6cacbfc0e6b5ae5dc7525773d89a69a3
parentd78532f462b2d0b514bbd3c1c3ed36135dca766c

Sema: resolve lazy values for compile log

Close #12204

2 files changed, 10 insertions(+), 0 deletions(-)

src/Sema.zig+5
...@@ -4508,6 +4508,7 @@ fn zirCompileLog(...@@ -4508,6 +4508,7 @@ fn zirCompileLog(
4508 const arg = try sema.resolveInst(arg_ref);4508 const arg = try sema.resolveInst(arg_ref);
4509 const arg_ty = sema.typeOf(arg);4509 const arg_ty = sema.typeOf(arg);
4510 if (try sema.resolveMaybeUndefVal(block, src, arg)) |val| {4510 if (try sema.resolveMaybeUndefVal(block, src, arg)) |val| {
4511 try sema.resolveLazyValue(block, src, val);
4511 try writer.print("@as({}, {})", .{4512 try writer.print("@as({}, {})", .{
4512 arg_ty.fmt(sema.mod), val.fmtValue(arg_ty, sema.mod),4513 arg_ty.fmt(sema.mod), val.fmtValue(arg_ty, sema.mod),
4513 });4514 });
...@@ -25440,6 +25441,10 @@ fn resolveLazyValue(...@@ -25440,6 +25441,10 @@ fn resolveLazyValue(
25440 const ty = val.castTag(.lazy_align).?.data;25441 const ty = val.castTag(.lazy_align).?.data;
25441 return sema.resolveTypeLayout(block, src, ty);25442 return sema.resolveTypeLayout(block, src, ty);
25442 },25443 },
25444 .lazy_size => {
25445 const ty = val.castTag(.lazy_size).?.data;
25446 return sema.resolveTypeLayout(block, src, ty);
25447 },
25443 else => return,25448 else => return,
25444 }25449 }
25445}25450}
test/cases/compile_errors/compile_log.zig+5
...@@ -6,9 +6,14 @@ fn bar(a: i32, b: []const u8) void {...@@ -6,9 +6,14 @@ fn bar(a: i32, b: []const u8) void {
6 @compileLog("a", a, "b", b);6 @compileLog("a", a, "b", b);
7 @compileLog("end",);7 @compileLog("end",);
8}8}
9export fn baz() void {
10 const S = struct { a: u32 };
11 @compileLog(@sizeOf(S));
12}
913
10// error14// error
11// backend=llvm15// backend=llvm
12// target=native16// target=native
13//17//
14// :5:5: error: found compile log statement18// :5:5: error: found compile log statement
19// :11:5: note: also here