diff --git a/src/Sema.zig b/src/Sema.zig index ed8a44a966..a1c7fa7b91 100644 --- 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 new file mode 100644 index 0000000000..1f3c4583cb --- /dev/null +++ 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