Skip to content

usize/isize vector comparison within function #4334

@travisstaloch

Description

@travisstaloch

on 30 Jan 2020 with zig version 0.5.0+7ebc624a1 pulled and built from master last night.

In the following code, two @Vector(4, usize) are compared with == in the test scope with no problem. However if the same comparison is made within a struct fn, the == comparison results in:

error: expected type '@Vector(4, u64)', found '@Vector(4, usize)'

It appears that the lhs @Vector(4, usize) is being converted to @Vector(4, u64) when it gets passed into a function. This error is not observed with u64 vector type.

//
// $ zig test repro.zig
// ./repro.zig:15:29: error: expected type '@Vector(4, u64)', found '@Vector(4, usize)'
//             const eqs = self.limbs == other.limbs; // <--- here
//                             ^
// ./repro.zig:15:36: note: referenced here
//             const eqs = self.limbs == other.limbs; // <--- here
//                                    ^
//

test "repro: vector == with usize/isize" {
    const S = struct {
        limbs: @Vector(4, usize), // this error also occurs with isize
        pub fn equals(self: @This(), other: @This()) bool {
            // error: expected type '@Vector(1, u64)', found '@Vector(1, usize)'
            const eqs = self.limbs == other.limbs; // <--- here
            return true;
        }
    };
    const s1 = S{ .limbs = @splat(4, @as(usize, 0)) };
    const s2 = S{ .limbs = @splat(4, @as(usize, 0)) };
    const eqs = s1.limbs == s2.limbs; // here == with usize vectors is ok
    const eq = s1.equals(s2);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorstage1The process of building from source via WebAssembly and the C backend.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions