Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.mem.eql not working with array of types #19929

Open
tgirod opened this issue May 10, 2024 · 0 comments · May be fixed by #19968
Open

std.mem.eql not working with array of types #19929

tgirod opened this issue May 10, 2024 · 0 comments · May be fixed by #19968
Labels
bug Observed behavior contradicts documented or intended behavior standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@tgirod
Copy link

tgirod commented May 10, 2024

Zig Version

0.12.0

Steps to Reproduce and Observed Behavior

const std = @import("std");

pub fn main() void {
    const a = [_]type{ bool, f32 };
    const b = [_]type{ u8, bool };
    const c = [_]type{bool};
    std.debug.print("{}\n", .{std.mem.eql(type, &a, &b)});
    // true
    std.debug.print("{}\n", .{std.mem.eql(type, &a, &c)});
    // true
}

Expected Behavior

I would expect std.mem.eql to work also with []type arrays, but the function always return true if the size of elements == 0, which is the case for type.

@tgirod tgirod added the bug Observed behavior contradicts documented or intended behavior label May 10, 2024
@Vexu Vexu added the standard library This issue involves writing Zig code for the standard library. label May 10, 2024
@Vexu Vexu added this to the 0.13.0 milestone May 10, 2024
wooster0 added a commit to wooster0/zig that referenced this issue May 14, 2024
The `if (@sizeof(T) == 0) return true;` check simply doesn't work for a number
of cases so that is removed and changed into `@sizeOf(T) != 0` and then
used in the `eqlBytes` check chain to make comparing `enum{}`s possible.

Fixes ziglang#19929
wooster0 added a commit to wooster0/zig that referenced this issue May 14, 2024
The `if (@sizeof(T) == 0) return true;` check simply doesn't work for a number
of cases so that is removed and changed into `@sizeOf(T) != 0` and then
used in the `eqlBytes` check chain to make comparing `enum{}`s possible.

The rest special-cases for comptime-only types and undefined to make
those comparisons possible as well.

Fixes ziglang#19929
wooster0 added a commit to wooster0/zig that referenced this issue May 14, 2024
The `if (@sizeof(T) == 0) return true;` check simply doesn't work for a number
of cases so that is removed and changed into `@sizeOf(T) != 0` and then
used in the `eqlBytes` check chain to make comparing `enum{}`s possible.

The rest special-cases for comptime-only types and undefined to make
those comparisons possible as well.

Fixes ziglang#19929
wooster0 added a commit to wooster0/zig that referenced this issue May 14, 2024
The `if (@sizeof(T) == 0) return true;` check simply doesn't work for a number
of cases so that is removed and changed into `@sizeOf(T) != 0` and then
used in the `eqlBytes` check chain to make comparing `enum{}`s possible.

The rest special-cases for comptime-only types and undefined to make
those comparisons possible as well.

Fixes ziglang#19929
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants