Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
zig-version: ["0.14.1"]

steps:
- uses: actions/checkout@v3

- name: Install Zig
uses: goto-bus-stop/setup-zig@v2
with:
version: 0.13.0
version: ${{ matrix.zig-version }}

- name: Check Zig Version
run: zig version
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
zig-cache
zig-out
.zig-cache
.zig-out
5 changes: 3 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
.{
.name = "interface",
.fingerprint = 0x34f4ecdd27565918,
.name = .interface,
// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.1",
.version = "0.0.2",

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
Expand Down
34 changes: 17 additions & 17 deletions src/interface.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ fn isTypeCompatible(comptime T1: type, comptime T2: type) bool {
if (@intFromEnum(info1) != @intFromEnum(info2)) return false;

return switch (info1) {
.Struct => |s1| blk: {
const s2 = @typeInfo(T2).Struct;
.@"struct" => |s1| blk: {
const s2 = @typeInfo(T2).@"struct";
if (s1.fields.len != s2.fields.len) break :blk false;
if (s1.is_tuple != s2.is_tuple) break :blk false;

Expand All @@ -23,8 +23,8 @@ fn isTypeCompatible(comptime T1: type, comptime T2: type) bool {
}
break :blk true;
},
.Enum => |e1| blk: {
const e2 = @typeInfo(T2).Enum;
.@"enum" => |e1| blk: {
const e2 = @typeInfo(T2).@"enum";
if (e1.fields.len != e2.fields.len) break :blk false;

for (e1.fields, e2.fields) |f1, f2| {
Expand All @@ -33,20 +33,20 @@ fn isTypeCompatible(comptime T1: type, comptime T2: type) bool {
}
break :blk true;
},
.Array => |a1| blk: {
const a2 = @typeInfo(T2).Array;
.array => |a1| blk: {
const a2 = @typeInfo(T2).array;
if (a1.len != a2.len) break :blk false;
break :blk isTypeCompatible(a1.child, a2.child);
},
.Pointer => |p1| blk: {
const p2 = @typeInfo(T2).Pointer;
.pointer => |p1| blk: {
const p2 = @typeInfo(T2).pointer;
if (p1.size != p2.size) break :blk false;
if (p1.is_const != p2.is_const) break :blk false;
if (p1.is_volatile != p2.is_volatile) break :blk false;
break :blk isTypeCompatible(p1.child, p2.child);
},
.Optional => |o1| blk: {
const o2 = @typeInfo(T2).Optional;
.optional => |o1| blk: {
const o2 = @typeInfo(T2).optional;
break :blk isTypeCompatible(o1.child, o2.child);
},
else => T1 == T2,
Expand Down Expand Up @@ -170,8 +170,8 @@ fn formatTypeMismatch(
///
pub fn Interface(comptime methods: anytype, comptime embedded: anytype) type {
const embedded_interfaces = switch (@typeInfo(@TypeOf(embedded))) {
.Null => embedded,
.Struct => |s| if (s.is_tuple) embedded else .{embedded},
.null => embedded,
.@"struct" => |s| if (s.is_tuple) embedded else .{embedded},
else => .{embedded},
};

Expand Down Expand Up @@ -325,12 +325,12 @@ pub fn Interface(comptime methods: anytype, comptime embedded: anytype) type {
const exp_info = @typeInfo(Expected);
const act_info = @typeInfo(Actual);

if (exp_info != .ErrorUnion or act_info != .ErrorUnion) {
if (exp_info != .error_union or act_info != .error_union) {
return Expected == Actual;
}

if (exp_info.ErrorUnion.error_set == anyerror) {
return exp_info.ErrorUnion.payload == act_info.ErrorUnion.payload;
if (exp_info.error_union.error_set == anyerror) {
return exp_info.error_union.payload == act_info.error_union.payload;
}
return Expected == Actual;
}
Expand Down Expand Up @@ -366,8 +366,8 @@ pub fn Interface(comptime methods: anytype, comptime embedded: anytype) type {
const impl_fn = @TypeOf(@field(Type, field.name));
const expected_fn = @field(methods, field.name);

const impl_info = @typeInfo(impl_fn).Fn;
const expected_info = @typeInfo(expected_fn).Fn;
const impl_info = @typeInfo(impl_fn).@"fn";
const expected_info = @typeInfo(expected_fn).@"fn";

if (impl_info.params.len != expected_info.params.len) {
problems = problems ++ &[_]Incompatibility{.{
Expand Down
Loading