| author | |
| committer | |
| log | 4a8121c1abfe6ffe9c6720e2841d80a36927b11a |
| tree | b6eaecaf340b315bf4a218c5711aab676d5e316c |
| parent | 4e8553660405a063d8abd335a600714af121aed9 |
4 files changed, 34 insertions(+), 30 deletions(-)
src/Sema.zig+2-1| ... | @@ -18707,13 +18707,14 @@ fn typeInfoNamespaceDecls( | ... | @@ -18707,13 +18707,14 @@ fn typeInfoNamespaceDecls( |
| 18707 | const decls = namespace.decls.keys(); | 18707 | const decls = namespace.decls.keys(); |
| 18708 | for (decls) |decl_index| { | 18708 | for (decls) |decl_index| { |
| 18709 | const decl = mod.declPtr(decl_index); | 18709 | const decl = mod.declPtr(decl_index); |
| 18710 | if (!decl.is_pub) continue; | ||
| 18710 | if (decl.kind == .@"usingnamespace") { | 18711 | if (decl.kind == .@"usingnamespace") { |
| 18711 | if (decl.analysis == .in_progress) continue; | 18712 | if (decl.analysis == .in_progress) continue; |
| 18712 | try mod.ensureDeclAnalyzed(decl_index); | 18713 | try mod.ensureDeclAnalyzed(decl_index); |
| 18713 | try sema.typeInfoNamespaceDecls(block, decl.val.toType().getNamespaceIndex(mod), declaration_ty, decl_vals, seen_namespaces); | 18714 | try sema.typeInfoNamespaceDecls(block, decl.val.toType().getNamespaceIndex(mod), declaration_ty, decl_vals, seen_namespaces); |
| 18714 | continue; | 18715 | continue; |
| 18715 | } | 18716 | } |
| 18716 | if (decl.kind != .named or !decl.is_pub) continue; | 18717 | if (decl.kind != .named) continue; |
| 18717 | const name_val = v: { | 18718 | const name_val = v: { |
| 18718 | // TODO: write something like getCoercedInts to avoid needing to dupe | 18719 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 18719 | const name = try sema.arena.dupeZ(u8, ip.stringToSlice(decl.name)); | 18720 | const name = try sema.arena.dupeZ(u8, ip.stringToSlice(decl.name)); |
test/behavior.zig-1| ... | @@ -97,7 +97,6 @@ test { | ... | @@ -97,7 +97,6 @@ test { |
| 97 | _ = @import("behavior/tuple_declarations.zig"); | 97 | _ = @import("behavior/tuple_declarations.zig"); |
| 98 | _ = @import("behavior/type.zig"); | 98 | _ = @import("behavior/type.zig"); |
| 99 | _ = @import("behavior/type_info.zig"); | 99 | _ = @import("behavior/type_info.zig"); |
| 100 | _ = @import("behavior/type_info_only_pub_decls.zig"); | ||
| 101 | _ = @import("behavior/type_info_mul_linksection_addrspace_decls.zig"); | 100 | _ = @import("behavior/type_info_mul_linksection_addrspace_decls.zig"); |
| 102 | _ = @import("behavior/typename.zig"); | 101 | _ = @import("behavior/typename.zig"); |
| 103 | _ = @import("behavior/undefined.zig"); | 102 | _ = @import("behavior/undefined.zig"); |
test/behavior/type_info.zig+32-4| ... | @@ -571,11 +571,13 @@ test "typeInfo resolves usingnamespace declarations" { | ... | @@ -571,11 +571,13 @@ test "typeInfo resolves usingnamespace declarations" { |
| 571 | 571 | ||
| 572 | const B = struct { | 572 | const B = struct { |
| 573 | pub const f0 = 42; | 573 | pub const f0 = 42; |
| 574 | usingnamespace A; | 574 | pub usingnamespace A; |
| 575 | }; | 575 | }; |
| 576 | 576 | ||
| 577 | try expect(@typeInfo(B).Struct.decls.len == 2); | 577 | const decls = @typeInfo(B).Struct.decls; |
| 578 | //a | 578 | try expect(decls.len == 2); |
| 579 | try expectEqualStrings(decls[0].name, "f0"); | ||
| 580 | try expectEqualStrings(decls[1].name, "f1"); | ||
| 579 | } | 581 | } |
| 580 | 582 | ||
| 581 | test "value from struct @typeInfo default_value can be loaded at comptime" { | 583 | test "value from struct @typeInfo default_value can be loaded at comptime" { |
| ... | @@ -596,7 +598,7 @@ test "@typeInfo decls and usingnamespace" { | ... | @@ -596,7 +598,7 @@ test "@typeInfo decls and usingnamespace" { |
| 596 | comptime {} | 598 | comptime {} |
| 597 | }; | 599 | }; |
| 598 | const B = struct { | 600 | const B = struct { |
| 599 | usingnamespace A; | 601 | pub usingnamespace A; |
| 600 | pub const z = 56; | 602 | pub const z = 56; |
| 601 | 603 | ||
| 602 | test {} | 604 | test {} |
| ... | @@ -626,3 +628,29 @@ test "type info of tuple of string literal default value" { | ... | @@ -626,3 +628,29 @@ test "type info of tuple of string literal default value" { |
| 626 | const value = @as(*align(1) const *const [2:0]u8, @ptrCast(struct_field.default_value.?)).*; | 628 | const value = @as(*align(1) const *const [2:0]u8, @ptrCast(struct_field.default_value.?)).*; |
| 627 | comptime std.debug.assert(value[0] == 'h'); | 629 | comptime std.debug.assert(value[0] == 'h'); |
| 628 | } | 630 | } |
| 631 | |||
| 632 | test "@typeInfo only contains pub decls" { | ||
| 633 | const other = struct { | ||
| 634 | const std = @import("std"); | ||
| 635 | |||
| 636 | usingnamespace struct { | ||
| 637 | pub const inside_non_pub_usingnamespace = 0; | ||
| 638 | }; | ||
| 639 | |||
| 640 | pub const Enum = enum { | ||
| 641 | a, | ||
| 642 | b, | ||
| 643 | c, | ||
| 644 | }; | ||
| 645 | |||
| 646 | pub const Struct = struct { | ||
| 647 | foo: i32, | ||
| 648 | }; | ||
| 649 | }; | ||
| 650 | const ti = @typeInfo(other); | ||
| 651 | const decls = ti.Struct.decls; | ||
| 652 | |||
| 653 | try std.testing.expectEqual(2, decls.len); | ||
| 654 | try std.testing.expectEqualStrings("Enum", decls[0].name); | ||
| 655 | try std.testing.expectEqualStrings("Struct", decls[1].name); | ||
| 656 | } |
test/behavior/type_info_only_pub_decls.zig deleted-24| ... | @@ -1,24 +0,0 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | const std = @import("std"); | ||
| 3 | const other = struct { | ||
| 4 | const std = @import("std"); | ||
| 5 | |||
| 6 | pub const Enum = enum { | ||
| 7 | a, | ||
| 8 | b, | ||
| 9 | c, | ||
| 10 | }; | ||
| 11 | |||
| 12 | pub const Struct = struct { | ||
| 13 | foo: i32, | ||
| 14 | }; | ||
| 15 | }; | ||
| 16 | |||
| 17 | test { | ||
| 18 | const ti = @typeInfo(other); | ||
| 19 | const decls = ti.Struct.decls; | ||
| 20 | |||
| 21 | try std.testing.expectEqual(2, decls.len); | ||
| 22 | try std.testing.expectEqualStrings("Enum", decls[0].name); | ||
| 23 | try std.testing.expectEqualStrings("Struct", decls[1].name); | ||
| 24 | } | ||