Skip to content

Peer Type Resolution fails with Homogeneous tuple and array. #15138

@PastMoments

Description

@PastMoments

Zig Version

0.10.1

Steps to Reproduce and Observed Behavior

Coercing from a homogeneous tuple to an array works as it should. However, peer type resolution between the two same types will fail.

const std = @import("std");
test {
    const x: [8]i16 = .{ 1, 2, 3, 4, 5, 6, 7, 8 };
    const y = .{ 1, 2, 3, 4, 5, 6, 7, 8 };

    const a = @as(@TypeOf(x), y); // This passes, as it should. (Tuple coerced to array)
    const T = @TypeOf(x, y); // This fails
    const b = (x == y); // This also fails


   _ = a;  _ = T; _ = b;
}

This appears to contradict this line in the documentation: This kind of type resolution chooses a type that all peer types can coerce into. Both the types coerce into the array, thus the peer type resolution should succeed.

Side question: Is there a reason an array can't coerce into a tuple?

Expected Behavior

In the above example, @TypeOf(x,y) should give [8]i16.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions