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

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

Closed
PastMoments opened this issue Apr 1, 2023 · 0 comments · Fixed by #15726
Closed

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

PastMoments opened this issue Apr 1, 2023 · 0 comments · Fixed by #15726
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase.
Milestone

Comments

@PastMoments
Copy link

PastMoments commented Apr 1, 2023

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.

@PastMoments PastMoments added the bug Observed behavior contradicts documented or intended behavior label Apr 1, 2023
@Vexu Vexu added enhancement Solving this issue will likely involve adding new logic or components to the codebase. and removed bug Observed behavior contradicts documented or intended behavior labels Apr 2, 2023
@Vexu Vexu added this to the 0.12.0 milestone Apr 2, 2023
mlugg added a commit to mlugg/zig that referenced this issue May 21, 2023
The existing logic for peer type resolution was quite convoluted and
buggy. This rewrite makes it much more resilient, readable, and
extensible. The algorithm works by first iterating over the types to
select a "strategy", then applying that strategy, possibly applying peer
resolution recursively.

Several new tests have been added to cover cases which the old logic did
not correctly handle.

Resolves: ziglang#15138
Resolves: ziglang#15644
Resolves: ziglang#15693
Resolves: ziglang#15709
Resolves: ziglang#15752
mlugg added a commit to mlugg/zig that referenced this issue May 21, 2023
The existing logic for peer type resolution was quite convoluted and
buggy. This rewrite makes it much more resilient, readable, and
extensible. The algorithm works by first iterating over the types to
select a "strategy", then applying that strategy, possibly applying peer
resolution recursively.

Several new tests have been added to cover cases which the old logic did
not correctly handle.

Resolves: ziglang#15138
Resolves: ziglang#15644
Resolves: ziglang#15693
Resolves: ziglang#15709
Resolves: ziglang#15752
mlugg added a commit to mlugg/zig that referenced this issue May 21, 2023
The existing logic for peer type resolution was quite convoluted and
buggy. This rewrite makes it much more resilient, readable, and
extensible. The algorithm works by first iterating over the types to
select a "strategy", then applying that strategy, possibly applying peer
resolution recursively.

Several new tests have been added to cover cases which the old logic did
not correctly handle.

Resolves: ziglang#15138
Resolves: ziglang#15644
Resolves: ziglang#15693
Resolves: ziglang#15709
Resolves: ziglang#15752
mlugg added a commit to mlugg/zig that referenced this issue Jun 13, 2023
The existing logic for peer type resolution was quite convoluted and
buggy. This rewrite makes it much more resilient, readable, and
extensible. The algorithm works by first iterating over the types to
select a "strategy", then applying that strategy, possibly applying peer
resolution recursively.

Several new tests have been added to cover cases which the old logic did
not correctly handle.

Resolves: ziglang#15138
Resolves: ziglang#15644
Resolves: ziglang#15693
Resolves: ziglang#15709
Resolves: ziglang#15752
@andrewrk andrewrk modified the milestones: 0.12.0, 0.11.0 Jun 13, 2023
mlugg added a commit to mlugg/zig that referenced this issue Jun 13, 2023
The existing logic for peer type resolution was quite convoluted and
buggy. This rewrite makes it much more resilient, readable, and
extensible. The algorithm works by first iterating over the types to
select a "strategy", then applying that strategy, possibly applying peer
resolution recursively.

Several new tests have been added to cover cases which the old logic did
not correctly handle.

Resolves: ziglang#15138
Resolves: ziglang#15644
Resolves: ziglang#15693
Resolves: ziglang#15709
Resolves: ziglang#15752
wooster0 pushed a commit to wooster0/zig that referenced this issue Jun 15, 2023
The existing logic for peer type resolution was quite convoluted and
buggy. This rewrite makes it much more resilient, readable, and
extensible. The algorithm works by first iterating over the types to
select a "strategy", then applying that strategy, possibly applying peer
resolution recursively.

Several new tests have been added to cover cases which the old logic did
not correctly handle.

Resolves: ziglang#15138
Resolves: ziglang#15644
Resolves: ziglang#15693
Resolves: ziglang#15709
Resolves: ziglang#15752
wooster0 pushed a commit to wooster0/zig that referenced this issue Jun 15, 2023
The existing logic for peer type resolution was quite convoluted and
buggy. This rewrite makes it much more resilient, readable, and
extensible. The algorithm works by first iterating over the types to
select a "strategy", then applying that strategy, possibly applying peer
resolution recursively.

Several new tests have been added to cover cases which the old logic did
not correctly handle.

Resolves: ziglang#15138
Resolves: ziglang#15644
Resolves: ziglang#15693
Resolves: ziglang#15709
Resolves: ziglang#15752
wooster0 pushed a commit to wooster0/zig that referenced this issue Jun 15, 2023
The existing logic for peer type resolution was quite convoluted and
buggy. This rewrite makes it much more resilient, readable, and
extensible. The algorithm works by first iterating over the types to
select a "strategy", then applying that strategy, possibly applying peer
resolution recursively.

Several new tests have been added to cover cases which the old logic did
not correctly handle.

Resolves: ziglang#15138
Resolves: ziglang#15644
Resolves: ziglang#15693
Resolves: ziglang#15709
Resolves: ziglang#15752
wooster0 pushed a commit to wooster0/zig that referenced this issue Jun 15, 2023
The existing logic for peer type resolution was quite convoluted and
buggy. This rewrite makes it much more resilient, readable, and
extensible. The algorithm works by first iterating over the types to
select a "strategy", then applying that strategy, possibly applying peer
resolution recursively.

Several new tests have been added to cover cases which the old logic did
not correctly handle.

Resolves: ziglang#15138
Resolves: ziglang#15644
Resolves: ziglang#15693
Resolves: ziglang#15709
Resolves: ziglang#15752
wooster0 pushed a commit to wooster0/zig that referenced this issue Jun 15, 2023
The existing logic for peer type resolution was quite convoluted and
buggy. This rewrite makes it much more resilient, readable, and
extensible. The algorithm works by first iterating over the types to
select a "strategy", then applying that strategy, possibly applying peer
resolution recursively.

Several new tests have been added to cover cases which the old logic did
not correctly handle.

Resolves: ziglang#15138
Resolves: ziglang#15644
Resolves: ziglang#15693
Resolves: ziglang#15709
Resolves: ziglang#15752
wooster0 pushed a commit to wooster0/zig that referenced this issue Jun 15, 2023
The existing logic for peer type resolution was quite convoluted and
buggy. This rewrite makes it much more resilient, readable, and
extensible. The algorithm works by first iterating over the types to
select a "strategy", then applying that strategy, possibly applying peer
resolution recursively.

Several new tests have been added to cover cases which the old logic did
not correctly handle.

Resolves: ziglang#15138
Resolves: ziglang#15644
Resolves: ziglang#15693
Resolves: ziglang#15709
Resolves: ziglang#15752
TUSF pushed a commit to TUSF/zig that referenced this issue May 9, 2024
The existing logic for peer type resolution was quite convoluted and
buggy. This rewrite makes it much more resilient, readable, and
extensible. The algorithm works by first iterating over the types to
select a "strategy", then applying that strategy, possibly applying peer
resolution recursively.

Several new tests have been added to cover cases which the old logic did
not correctly handle.

Resolves: ziglang#15138
Resolves: ziglang#15644
Resolves: ziglang#15693
Resolves: ziglang#15709
Resolves: ziglang#15752
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase.
Projects
None yet
3 participants