From 5f3775b8130be3bc855cd4c554193b4dccb95062 Mon Sep 17 00:00:00 2001 From: jinzhongjia Date: Fri, 30 Aug 2024 20:16:35 +0800 Subject: [PATCH] fix master --- course/code/14/enum.zig | 6 +++--- course/code/14/optional_type.zig | 2 +- course/code/14/pointer.zig | 4 ++-- course/code/14/reflection.zig | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/course/code/14/enum.zig b/course/code/14/enum.zig index 27d83c3f..0a656b43 100644 --- a/course/code/14/enum.zig +++ b/course/code/14/enum.zig @@ -67,9 +67,9 @@ const EnumSize = struct { }; pub fn main() !void { - try expect(@typeInfo(Small).Enum.tag_type == u2); - try expect(@typeInfo(Small).Enum.fields.len == 4); - try expect(mem.eql(u8, @typeInfo(Small).Enum.fields[1].name, "two")); + try expect(@typeInfo(Small).@"enum".tag_type == u2); + try expect(@typeInfo(Small).@"enum".fields.len == 4); + try expect(mem.eql(u8, @typeInfo(Small).@"enum".fields[1].name, "two")); try expect(mem.eql(u8, @tagName(Small.three), "three")); } // #endregion enum_size diff --git a/course/code/14/optional_type.zig b/course/code/14/optional_type.zig index 7461d642..ab242483 100644 --- a/course/code/14/optional_type.zig +++ b/course/code/14/optional_type.zig @@ -53,7 +53,7 @@ const ComptimeAccessOptionalType = struct { foo = 1234; // 使用编译期反射来获取 foo 的类型信息 - try comptime expect(@typeInfo(@TypeOf(foo)).Optional.child == i32); + try comptime expect(@typeInfo(@TypeOf(foo)).optional.child == i32); // #endregion comptime_access_optional_type } }; diff --git a/course/code/14/pointer.zig b/course/code/14/pointer.zig index 3290ede3..de51acd7 100644 --- a/course/code/14/pointer.zig +++ b/course/code/14/pointer.zig @@ -114,7 +114,7 @@ const Align = struct { if (builtin.target.cpu.arch == .x86_64) { // 获取了 x86_64 架构的指针对齐大小 - try expect(@typeInfo(*i32).Pointer.alignment == 4); + try expect(@typeInfo(*i32).pointer.alignment == 4); } } // #endregion align @@ -137,7 +137,7 @@ const AlignCast = struct { pub fn main() !void { // 全局变量对齐 - try expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4); + try expect(@typeInfo(@TypeOf(&foo)).pointer.alignment == 4); try expect(@TypeOf(&foo) == *align(4) u8); const as_pointer_to_array: *align(4) [1]u8 = &foo; const as_slice: []align(4) u8 = as_pointer_to_array; diff --git a/course/code/14/reflection.zig b/course/code/14/reflection.zig index eb5086f8..6d03b27f 100644 --- a/course/code/14/reflection.zig +++ b/course/code/14/reflection.zig @@ -63,7 +63,7 @@ const typeInfo = struct { // 通过 @typeInfo 获取类型信息 const type_info = @typeInfo(T); // 断言它为 struct - const struct_info = type_info.Struct; + const struct_info = type_info.@"struct"; // inline for 打印该结构体内部字段的信息 inline for (struct_info.fields) |field| { @@ -82,7 +82,7 @@ const TypeInfo2 = struct { fn IntToArray(comptime T: type) type { // 获得类型信息,并断言为Int - const int_info = @typeInfo(T).Int; + const int_info = @typeInfo(T).int; // 获得Int位数 const bits = int_info.bits; // 检查位数是否被8整除 @@ -106,7 +106,7 @@ const TypeInfo3 = struct { fn ExternAlignOne(comptime T: type) type { // 获得类型信息,并断言为Struct. - comptime var struct_info = @typeInfo(T).Struct; + comptime var struct_info = @typeInfo(T).@"struct"; // 将内存布局改为 extern struct_info.layout = .@"extern"; // 复制字段信息(原为只读切片,故需复制) @@ -116,7 +116,7 @@ const TypeInfo3 = struct { // 替换字段定义 struct_info.fields = &new_fields; // 重新构造类型 - return @Type(.{ .Struct = struct_info }); + return @Type(.{ .@"struct" = struct_info }); } const MyStruct = struct { @@ -245,7 +245,7 @@ const Type = struct { const std = @import("std"); const T = @Type(.{ - .Struct = .{ + .@"struct" = .{ .layout = .auto, .fields = &.{ .{