Skip to content

function returning type taking anonymous struct as argument has equal type name when types are not equal #21904

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

Open
paperclover opened this issue Nov 4, 2024 · 0 comments
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Milestone

Comments

@paperclover
Copy link
Contributor

Zig Version

0.14.0-dev.2126+e27b4647d

Steps to Reproduce and Observed Output

fn Wrap(content: anytype) type {
    return struct {
        x: u32,

        comptime {
            _ = content;
        }
    };
}

pub fn main() void {
    const A = Wrap(.{ .hello = 1 });
    const B = Wrap(.{ .hello = 1 });
    const b: A = @as(B, .{ .x = 2 });
    _ = b;
}
repro.zig:14:18: error: expected type 'repro.Wrap(.{ .hello = 1 })', found 'repro.Wrap(.{ .hello = 1 })'

Expected Output

When I hit this error in a more complicated situation I realized it was from #21817, but only because i was already aware that change was going to happen. To someone who is unaware, this message is very odd because the types look to be the same.

I'm not sure exactly how to convey the two unique types. Maybe at the minimum using a note saying that different instantiations of anonymous unions create different types, or the struct name shouldn't be . but some generated name.

@paperclover paperclover added the error message This issue points out an error message that is unhelpful and should be improved. label Nov 4, 2024
@Vexu Vexu added this to the 0.14.0 milestone Nov 4, 2024
@andrewrk andrewrk modified the milestones: 0.14.0, unplanned Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Projects
None yet
Development

No branches or pull requests

3 participants