diff --git a/src/Sema.zig b/src/Sema.zig index 40f929b778..39d687c18a 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -18707,13 +18707,14 @@ fn typeInfoNamespaceDecls( const decls = namespace.decls.keys(); for (decls) |decl_index| { const decl = mod.declPtr(decl_index); + if (!decl.is_pub) continue; if (decl.kind == .@"usingnamespace") { if (decl.analysis == .in_progress) continue; try mod.ensureDeclAnalyzed(decl_index); try sema.typeInfoNamespaceDecls(block, decl.val.toType().getNamespaceIndex(mod), declaration_ty, decl_vals, seen_namespaces); continue; } - if (decl.kind != .named or !decl.is_pub) continue; + if (decl.kind != .named) continue; const name_val = v: { // TODO: write something like getCoercedInts to avoid needing to dupe const name = try sema.arena.dupeZ(u8, ip.stringToSlice(decl.name)); diff --git a/test/behavior.zig b/test/behavior.zig index 841bc0483b..3081f6c9f9 100644 --- a/test/behavior.zig +++ b/test/behavior.zig @@ -97,7 +97,6 @@ test { _ = @import("behavior/tuple_declarations.zig"); _ = @import("behavior/type.zig"); _ = @import("behavior/type_info.zig"); - _ = @import("behavior/type_info_only_pub_decls.zig"); _ = @import("behavior/type_info_mul_linksection_addrspace_decls.zig"); _ = @import("behavior/typename.zig"); _ = @import("behavior/undefined.zig"); diff --git a/test/behavior/type_info.zig b/test/behavior/type_info.zig index 0d54b14c39..b650248e42 100644 --- a/test/behavior/type_info.zig +++ b/test/behavior/type_info.zig @@ -571,11 +571,13 @@ test "typeInfo resolves usingnamespace declarations" { const B = struct { pub const f0 = 42; - usingnamespace A; + pub usingnamespace A; }; - try expect(@typeInfo(B).Struct.decls.len == 2); - //a + const decls = @typeInfo(B).Struct.decls; + try expect(decls.len == 2); + try expectEqualStrings(decls[0].name, "f0"); + try expectEqualStrings(decls[1].name, "f1"); } test "value from struct @typeInfo default_value can be loaded at comptime" { @@ -596,7 +598,7 @@ test "@typeInfo decls and usingnamespace" { comptime {} }; const B = struct { - usingnamespace A; + pub usingnamespace A; pub const z = 56; test {} @@ -626,3 +628,29 @@ test "type info of tuple of string literal default value" { const value = @as(*align(1) const *const [2:0]u8, @ptrCast(struct_field.default_value.?)).*; comptime std.debug.assert(value[0] == 'h'); } + +test "@typeInfo only contains pub decls" { + const other = struct { + const std = @import("std"); + + usingnamespace struct { + pub const inside_non_pub_usingnamespace = 0; + }; + + pub const Enum = enum { + a, + b, + c, + }; + + pub const Struct = struct { + foo: i32, + }; + }; + const ti = @typeInfo(other); + const decls = ti.Struct.decls; + + try std.testing.expectEqual(2, decls.len); + try std.testing.expectEqualStrings("Enum", decls[0].name); + try std.testing.expectEqualStrings("Struct", decls[1].name); +} diff --git a/test/behavior/type_info_only_pub_decls.zig b/test/behavior/type_info_only_pub_decls.zig deleted file mode 100644 index 5d08d631b9..0000000000 --- a/test/behavior/type_info_only_pub_decls.zig +++ /dev/null @@ -1,24 +0,0 @@ -const builtin = @import("builtin"); -const std = @import("std"); -const other = struct { - const std = @import("std"); - - pub const Enum = enum { - a, - b, - c, - }; - - pub const Struct = struct { - foo: i32, - }; -}; - -test { - const ti = @typeInfo(other); - const decls = ti.Struct.decls; - - try std.testing.expectEqual(2, decls.len); - try std.testing.expectEqualStrings("Enum", decls[0].name); - try std.testing.expectEqualStrings("Struct", decls[1].name); -}