authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-17 16:39:44+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-19 01:38:19+03:00
log4aaff75c8191b9cff40d3423f44bdb831a88d89b
treedb731a48944773e52472cbbfe239e9ab01d8a3ed
parent6582896ee00cd6b05b2f0a1d845b4a77d6bf7c25

Sema: resolve tuple default values before hashing

Closes #12488

3 files changed, 43 insertions(+), 0 deletions(-)

src/Sema.zig+29
......@@ -6622,6 +6622,11 @@ fn instantiateGenericCall(
66226622 }
66236623
66246624 const arg_ty = sema.typeOf(uncasted_args[i]);
6625 if (is_comptime or is_anytype) {
6626 // Tuple default values are a part of the type and need to be
6627 // resolved to hash the type.
6628 try sema.resolveTupleLazyValues(block, call_src, arg_ty);
6629 }
66256630
66266631 if (is_comptime) {
66276632 const arg_val = sema.analyzeGenericCallArgVal(block, .unneeded, uncasted_args[i]) catch |err| switch (err) {
......@@ -6997,6 +7002,16 @@ fn instantiateGenericCall(
69977002 return result;
69987003}
69997004
7005fn resolveTupleLazyValues(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!void {
7006 if (!ty.isTuple()) return;
7007 const tuple = ty.tupleFields();
7008 for (tuple.values) |field_val, i| {
7009 try sema.resolveTupleLazyValues(block, src, tuple.types[i]);
7010 if (field_val.tag() == .unreachable_value) continue;
7011 try sema.resolveLazyValue(block, src, field_val);
7012 }
7013}
7014
70007015fn emitDbgInline(
70017016 sema: *Sema,
70027017 block: *Block,
......@@ -28606,6 +28621,20 @@ fn resolveLazyValue(
2860628621 const ty = val.castTag(.lazy_size).?.data;
2860728622 return sema.resolveTypeLayout(block, src, ty);
2860828623 },
28624 .comptime_field_ptr => {
28625 const field_ptr = val.castTag(.comptime_field_ptr).?.data;
28626 return sema.resolveLazyValue(block, src, field_ptr.field_val);
28627 },
28628 .@"union" => {
28629 const union_val = val.castTag(.@"union").?.data;
28630 return sema.resolveLazyValue(block, src, union_val.val);
28631 },
28632 .aggregate => {
28633 const aggregate = val.castTag(.aggregate).?.data;
28634 for (aggregate) |elem_val| {
28635 try sema.resolveLazyValue(block, src, elem_val);
28636 }
28637 },
2860928638 else => return,
2861028639 }
2861128640}
test/behavior.zig+1
......@@ -88,6 +88,7 @@ test {
8888 _ = @import("behavior/bugs/12033.zig");
8989 _ = @import("behavior/bugs/12430.zig");
9090 _ = @import("behavior/bugs/12486.zig");
91 _ = @import("behavior/bugs/12488.zig");
9192 _ = @import("behavior/bugs/12551.zig");
9293 _ = @import("behavior/bugs/12644.zig");
9394 _ = @import("behavior/bugs/12680.zig");
test/behavior/bugs/12488.zig created+13
......@@ -0,0 +1,13 @@
1const expect = @import("std").testing.expect;
2
3const A = struct {
4 a: u32,
5};
6
7fn foo(comptime a: anytype) !void {
8 try expect(a[0][0] == @sizeOf(A));
9}
10
11test {
12 try foo(.{[_]usize{@sizeOf(A)}});
13}