authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-20 13:58:37+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-20 20:25:12+02:00
log9e276d32f3f8d980e4bf4c0a52df0fa97717aacb
tree05842a5d8694e59538d164771ddab648bcd898d8
parent9e7293619ffb26049af2248226a3d75ef274bfb0

Sema: fix memory management of missing field error

Closes #13590

2 files changed, 23 insertions(+), 4 deletions(-)

src/Sema.zig+5-4
......@@ -4111,6 +4111,7 @@ fn validateStructInit(
41114111 .{fqn},
41124112 );
41134113 }
4114 root_msg = null;
41144115 return sema.failWithOwnedErrorMsg(msg);
41154116 }
41164117
......@@ -4230,7 +4231,6 @@ fn validateStructInit(
42304231 }
42314232
42324233 if (root_msg) |msg| {
4233 root_msg = null;
42344234 if (struct_ty.castTag(.@"struct")) |struct_obj| {
42354235 const fqn = try struct_obj.data.getFullyQualifiedName(sema.mod);
42364236 defer gpa.free(fqn);
......@@ -4241,6 +4241,7 @@ fn validateStructInit(
42414241 .{fqn},
42424242 );
42434243 }
4244 root_msg = null;
42444245 return sema.failWithOwnedErrorMsg(msg);
42454246 }
42464247
......@@ -17098,7 +17099,6 @@ fn finishStructInit(
1709817099 }
1709917100
1710017101 if (root_msg) |msg| {
17101 root_msg = null;
1710217102 if (struct_ty.castTag(.@"struct")) |struct_obj| {
1710317103 const fqn = try struct_obj.data.getFullyQualifiedName(sema.mod);
1710417104 defer gpa.free(fqn);
......@@ -17109,6 +17109,7 @@ fn finishStructInit(
1710917109 .{fqn},
1711017110 );
1711117111 }
17112 root_msg = null;
1711217113 return sema.failWithOwnedErrorMsg(msg);
1711317114 }
1711417115
......@@ -27225,8 +27226,8 @@ fn coerceTupleToStruct(
2722527226 }
2722627227
2722727228 if (root_msg) |msg| {
27228 root_msg = null;
2722927229 try sema.addDeclaredHereNote(msg, struct_ty);
27230 root_msg = null;
2723027231 return sema.failWithOwnedErrorMsg(msg);
2723127232 }
2723227233
......@@ -27331,8 +27332,8 @@ fn coerceTupleToTuple(
2733127332 }
2733227333
2733327334 if (root_msg) |msg| {
27334 root_msg = null;
2733527335 try sema.addDeclaredHereNote(msg, tuple_ty);
27336 root_msg = null;
2733627337 return sema.failWithOwnedErrorMsg(msg);
2733727338 }
2733827339
test/cases/compile_errors/missing_struct_field_in_fn_called_at_comptime.zig created+18
......@@ -0,0 +1,18 @@
1const S = struct {
2 a: u32,
3 b: comptime_int,
4 fn init() S {
5 return .{ .a = 1 };
6 }
7};
8comptime {
9 _ = S.init();
10}
11
12// error
13// backend=stage2
14// target=native
15//
16// :5:17: error: missing struct field: b
17// :1:11: note: struct 'tmp.S' declared here
18// :9:15: note: called from here