diff --git a/src/Sema.zig b/src/Sema.zig index 8dc30ebbe5..c5cd2c9cd6 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -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, diff --git a/test/cases/compile_errors/bad_member_access_on_tuple.zig b/test/cases/compile_errors/bad_member_access_on_tuple.zig new file mode 100644 index 0000000000..0f91655fc0 --- /dev/null +++ b/test/cases/compile_errors/bad_member_access_on_tuple.zig @@ -0,0 +1,9 @@ +comptime { + _ = @TypeOf(.{}).is_optional; +} + +// error +// backend=stage2 +// target=native +// +// :2:21: error: struct '@TypeOf(.{})' has no member named 'is_optional'