mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
Sema: fix non-pub usingnamespace in @typeInfo
This commit is contained in:
parent
4e85536604
commit
4a8121c1ab
4 changed files with 34 additions and 30 deletions
|
|
@ -18707,13 +18707,14 @@ fn typeInfoNamespaceDecls(
|
||||||
const decls = namespace.decls.keys();
|
const decls = namespace.decls.keys();
|
||||||
for (decls) |decl_index| {
|
for (decls) |decl_index| {
|
||||||
const decl = mod.declPtr(decl_index);
|
const decl = mod.declPtr(decl_index);
|
||||||
|
if (!decl.is_pub) continue;
|
||||||
if (decl.kind == .@"usingnamespace") {
|
if (decl.kind == .@"usingnamespace") {
|
||||||
if (decl.analysis == .in_progress) continue;
|
if (decl.analysis == .in_progress) continue;
|
||||||
try mod.ensureDeclAnalyzed(decl_index);
|
try mod.ensureDeclAnalyzed(decl_index);
|
||||||
try sema.typeInfoNamespaceDecls(block, decl.val.toType().getNamespaceIndex(mod), declaration_ty, decl_vals, seen_namespaces);
|
try sema.typeInfoNamespaceDecls(block, decl.val.toType().getNamespaceIndex(mod), declaration_ty, decl_vals, seen_namespaces);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (decl.kind != .named or !decl.is_pub) continue;
|
if (decl.kind != .named) continue;
|
||||||
const name_val = v: {
|
const name_val = v: {
|
||||||
// TODO: write something like getCoercedInts to avoid needing to dupe
|
// TODO: write something like getCoercedInts to avoid needing to dupe
|
||||||
const name = try sema.arena.dupeZ(u8, ip.stringToSlice(decl.name));
|
const name = try sema.arena.dupeZ(u8, ip.stringToSlice(decl.name));
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,6 @@ test {
|
||||||
_ = @import("behavior/tuple_declarations.zig");
|
_ = @import("behavior/tuple_declarations.zig");
|
||||||
_ = @import("behavior/type.zig");
|
_ = @import("behavior/type.zig");
|
||||||
_ = @import("behavior/type_info.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/type_info_mul_linksection_addrspace_decls.zig");
|
||||||
_ = @import("behavior/typename.zig");
|
_ = @import("behavior/typename.zig");
|
||||||
_ = @import("behavior/undefined.zig");
|
_ = @import("behavior/undefined.zig");
|
||||||
|
|
|
||||||
|
|
@ -571,11 +571,13 @@ test "typeInfo resolves usingnamespace declarations" {
|
||||||
|
|
||||||
const B = struct {
|
const B = struct {
|
||||||
pub const f0 = 42;
|
pub const f0 = 42;
|
||||||
usingnamespace A;
|
pub usingnamespace A;
|
||||||
};
|
};
|
||||||
|
|
||||||
try expect(@typeInfo(B).Struct.decls.len == 2);
|
const decls = @typeInfo(B).Struct.decls;
|
||||||
//a
|
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" {
|
test "value from struct @typeInfo default_value can be loaded at comptime" {
|
||||||
|
|
@ -596,7 +598,7 @@ test "@typeInfo decls and usingnamespace" {
|
||||||
comptime {}
|
comptime {}
|
||||||
};
|
};
|
||||||
const B = struct {
|
const B = struct {
|
||||||
usingnamespace A;
|
pub usingnamespace A;
|
||||||
pub const z = 56;
|
pub const z = 56;
|
||||||
|
|
||||||
test {}
|
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.?)).*;
|
const value = @as(*align(1) const *const [2:0]u8, @ptrCast(struct_field.default_value.?)).*;
|
||||||
comptime std.debug.assert(value[0] == 'h');
|
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);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
Loading…
Add table
Reference in a new issue