Skip to content

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

Open
@paperclover

Description

@paperclover

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    error messageThis issue points out an error message that is unhelpful and should be improved.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions