commit 9e276d32f3f8d980e4bf4c0a52df0fa97717aacb (tree)
parent 9e7293619ffb26049af2248226a3d75ef274bfb0
Author: Veikka Tuominen <git@vexu.eu>
Date: Sun, 20 Nov 2022 13:58:37 +0200
Sema: fix memory management of missing field error
Closes #13590
Diffstat:
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/src/Sema.zig b/src/Sema.zig
@@ -4111,6 +4111,7 @@ fn validateStructInit(
.{fqn},
);
}
+ root_msg = null;
return sema.failWithOwnedErrorMsg(msg);
}
@@ -4230,7 +4231,6 @@ fn validateStructInit(
}
if (root_msg) |msg| {
- root_msg = null;
if (struct_ty.castTag(.@"struct")) |struct_obj| {
const fqn = try struct_obj.data.getFullyQualifiedName(sema.mod);
defer gpa.free(fqn);
@@ -4241,6 +4241,7 @@ fn validateStructInit(
.{fqn},
);
}
+ root_msg = null;
return sema.failWithOwnedErrorMsg(msg);
}
@@ -17098,7 +17099,6 @@ fn finishStructInit(
}
if (root_msg) |msg| {
- root_msg = null;
if (struct_ty.castTag(.@"struct")) |struct_obj| {
const fqn = try struct_obj.data.getFullyQualifiedName(sema.mod);
defer gpa.free(fqn);
@@ -17109,6 +17109,7 @@ fn finishStructInit(
.{fqn},
);
}
+ root_msg = null;
return sema.failWithOwnedErrorMsg(msg);
}
@@ -27225,8 +27226,8 @@ fn coerceTupleToStruct(
}
if (root_msg) |msg| {
- root_msg = null;
try sema.addDeclaredHereNote(msg, struct_ty);
+ root_msg = null;
return sema.failWithOwnedErrorMsg(msg);
}
@@ -27331,8 +27332,8 @@ fn coerceTupleToTuple(
}
if (root_msg) |msg| {
- root_msg = null;
try sema.addDeclaredHereNote(msg, tuple_ty);
+ root_msg = null;
return sema.failWithOwnedErrorMsg(msg);
}
diff --git a/test/cases/compile_errors/missing_struct_field_in_fn_called_at_comptime.zig b/test/cases/compile_errors/missing_struct_field_in_fn_called_at_comptime.zig
@@ -0,0 +1,18 @@
+const S = struct {
+ a: u32,
+ b: comptime_int,
+ fn init() S {
+ return .{ .a = 1 };
+ }
+};
+comptime {
+ _ = S.init();
+}
+
+// error
+// backend=stage2
+// target=native
+//
+// :5:17: error: missing struct field: b
+// :1:11: note: struct 'tmp.S' declared here
+// :9:15: note: called from here