Skip to content

Commit

Permalink
Fix compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sam701 committed Sep 5, 2024
1 parent 67e35c7 commit 78c8512
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
build_and_test:
strategy:
matrix:
zig-version: ['0.12.0', 'master']
zig-version: ['master']

runs-on: ubuntu-latest
name: Test / Zig ${{ matrix.zig-version }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
zig-cache/
zig-out/
zig-out/
.zig-cache
18 changes: 9 additions & 9 deletions src/struct_mapping.zig
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ pub const Context = struct {

pub fn intoStruct(ctx: *Context, comptime T: type, dest: *T, table: *Table) !void {
switch (@typeInfo(T)) {
.Struct => |info| {
.@"struct" => |info| {
inline for (info.fields) |field_info| {
try ctx.field_path.append(field_info.name);
if (table.fetchRemove(field_info.name)) |entry| {
try setValue(ctx, field_info.type, &@field(dest.*, field_info.name), &entry.value);
ctx.alloc.free(entry.key);
} else {
if (@typeInfo(field_info.type) == .Optional)
if (@typeInfo(field_info.type) == .optional)
@field(dest.*, field_info.name) = null
else if (field_info.default_value) |defaultValue| {
@field(dest.*, field_info.name) = @as(*const field_info.type, @alignCast(@ptrCast(defaultValue))).*;
Expand Down Expand Up @@ -86,15 +86,15 @@ fn setValue(ctx: *Context, comptime T: type, dest: *T, value: *const Value) !voi
else => {},
}
switch (@typeInfo(T)) {
.Int => {
.int => {
switch (value.*) {
.integer => |x| {
dest.* = @intCast(x);
},
else => return error.InvalidValueType,
}
},
.Float => {
.float => {
switch (value.*) {
.float => |x| {
dest.* = @floatCast(x);
Expand All @@ -105,15 +105,15 @@ fn setValue(ctx: *Context, comptime T: type, dest: *T, value: *const Value) !voi
else => return error.InvalidValueType,
}
},
.Bool => {
.bool => {
switch (value.*) {
.boolean => |b| {
dest.* = b;
},
else => return error.InvalidValueType,
}
},
.Pointer => |tinfo| {
.pointer => |tinfo| {
switch (tinfo.size) {
.One => {
dest.* = try ctx.alloc.create(tinfo.child);
Expand Down Expand Up @@ -150,7 +150,7 @@ fn setValue(ctx: *Context, comptime T: type, dest: *T, value: *const Value) !voi
},
}
},
.Struct => {
.@"struct" => {
switch (value.*) {
.table => |tab| {
try intoStruct(ctx, T, dest, tab);
Expand All @@ -159,10 +159,10 @@ fn setValue(ctx: *Context, comptime T: type, dest: *T, value: *const Value) !voi
else => return error.InvalidValueType,
}
},
.Optional => |tinfo| {
.optional => |tinfo| {
try setValue(ctx, tinfo.child, &dest.*.?, value);
},
.Enum => |tinfo| {
.@"enum" => |tinfo| {
switch (value.*) {
.string => |s| {
inline for (tinfo.fields) |field| {
Expand Down

2 comments on commit 78c8512

@darkyzhou
Copy link

@darkyzhou darkyzhou commented on 78c8512 Sep 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I started learning Zig yesterday.
It seems this commit breaks the compilation in Zig 0.13.0 in favor of master branch. I wonder if I should go with master branch too.

@sam701
Copy link
Owner Author

@sam701 sam701 commented on 78c8512 Sep 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darkyzhou you are right. This commit breaks the compatibility to 0.13. The thing is that zig is still a young, fast changing language, so most folks use the master. If you decide to stick with the 0.13, you can reference the previous commit in your build.zig.zon file.

Please sign in to comment.