Sema: fix unwrapping null when reporting error on member access

Closes #14399
This commit is contained in:
Veikka Tuominen 2023-01-21 23:17:02 +02:00
parent 5259d11e3b
commit 1f475de852
2 changed files with 11 additions and 2 deletions

View File

@ -4643,11 +4643,11 @@ fn failWithBadMemberAccess(
.Enum => "enum",
else => unreachable,
};
if (sema.mod.declIsRoot(agg_ty.getOwnerDecl())) {
if (agg_ty.getOwnerDeclOrNull()) |some| if (sema.mod.declIsRoot(some)) {
return sema.fail(block, field_src, "root struct of file '{}' has no member named '{s}'", .{
agg_ty.fmt(sema.mod), field_name,
});
}
};
const msg = msg: {
const msg = try sema.errMsg(block, field_src, "{s} '{}' has no member named '{s}'", .{
kw_name, agg_ty.fmt(sema.mod), field_name,

View File

@ -0,0 +1,9 @@
comptime {
_ = @TypeOf(.{}).is_optional;
}
// error
// backend=stage2
// target=native
//
// :2:21: error: struct '@TypeOf(.{})' has no member named 'is_optional'