Sema: fix memory management of missing field error

Closes #13590
This commit is contained in:
Veikka Tuominen 2022-11-20 13:58:37 +02:00
parent 9e7293619f
commit 9e276d32f3
2 changed files with 23 additions and 4 deletions

View File

@ -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);
}

View File

@ -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