authorgravatar for der.teufel.mail@gmail.comKrzysztof Wolicki <der.teufel.mail@gmail.com> 2024-01-26 14:22:15+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-01-26 15:22:15+02:00
log61ba225709b88579984a1a679021d121d1aada64
tree55734f93d5e8009c5beecec938ef0fe634ddd533
parentbea958df4d0c5fc38633f09b6490c16e24a03155
signaturebadge-check Signed by PGP key B5690EEEBB952194

Sema: tuples have no names to be used for reporting errors in finishStructInit


2 files changed, 29 insertions(+), 6 deletions(-)

src/Sema.zig+15-6
......@@ -19963,13 +19963,22 @@ fn finishStructInit(
1996319963
1996419964 const field_init = struct_type.fieldInit(ip, i);
1996519965 if (field_init == .none) {
19966 const field_name = struct_type.field_names.get(ip)[i];
19967 const template = "missing struct field: {}";
19968 const args = .{field_name.fmt(ip)};
19969 if (root_msg) |msg| {
19970 try sema.errNote(block, init_src, msg, template, args);
19966 if (!struct_type.isTuple(ip)) {
19967 const field_name = struct_type.field_names.get(ip)[i];
19968 const template = "missing struct field: {}";
19969 const args = .{field_name.fmt(ip)};
19970 if (root_msg) |msg| {
19971 try sema.errNote(block, init_src, msg, template, args);
19972 } else {
19973 root_msg = try sema.errMsg(block, init_src, template, args);
19974 }
1997119975 } else {
19972 root_msg = try sema.errMsg(block, init_src, template, args);
19976 const template = "missing tuple field with index {d}";
19977 if (root_msg) |msg| {
19978 try sema.errNote(block, init_src, msg, template, .{i});
19979 } else {
19980 root_msg = try sema.errMsg(block, init_src, template, .{i});
19981 }
1997319982 }
1997419983 } else {
1997519984 field_inits[i] = Air.internedToRef(field_init);
test/cases/compile_errors/missing_field_in_struct_value_expression.zig+14
......@@ -13,9 +13,23 @@ export fn f() void {
1313 _ = a;
1414}
1515
16const B = struct { u32, u32 };
17export fn g() void {
18 const b = B{0};
19 _ = b;
20}
21export fn h() void {
22 const c = B{};
23 _ = c;
24}
1625// error
1726// backend=stage2
1827// target=native
1928//
2029// :9:16: error: missing struct field: x
2130// :1:11: note: struct 'tmp.A' declared here
31// :18:16: error: missing tuple field with index 1
32// :16:11: note: struct declared here
33// :22:16: error: missing tuple field with index 0
34// :22:16: note: missing tuple field with index 1
35// :16:11: note: struct 'tmp.B' declared here