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

Invalid error on implicit cast from slice of sentinel terminated slices #23016

Open
Vexu opened this issue Feb 26, 2025 · 2 comments
Open

Invalid error on implicit cast from slice of sentinel terminated slices #23016

Vexu opened this issue Feb 26, 2025 · 2 comments
Labels
error message This issue points out an error message that is unhelpful and should be improved.
Milestone

Comments

@Vexu
Copy link
Member

Vexu commented Feb 26, 2025

Zig Version

0.14.0-dev.3357+c44f4501e

Steps to Reproduce and Observed Behavior

comptime {
    const a: [][:0]const u8 = undefined;
    const b: [][]const u8 = a;
    _ = b;
}
a.zig:15:29: error: expected type '[][]const u8', found '[][:0]const u8'
    const b: [][]const u8 = a;
                            ^
a.zig:15:29: note: pointer type child '[:0]const u8' cannot cast into pointer type child '[]const u8'
a.zig:15:29: note: pointer sentinel '0' cannot cast into pointer sentinel 'unreachable'

Expected Behavior

No mention of pointer sentinel 'unreachable'.

@Vexu Vexu added the bug Observed behavior contradicts documented or intended behavior label Feb 26, 2025
@silversquirl
Copy link
Contributor

this seems intended to me? b gives a view into a that allows setting elements to non-terminated slices, just like how eg. casting []*T to []?*T is not allowed but []const *T to []const ?*T is.

@Vexu
Copy link
Member Author

Vexu commented Feb 26, 2025

Oh right, I didn't think of the missing const.

The error message is still incorrect though.

@Vexu Vexu added error message This issue points out an error message that is unhelpful and should be improved. and removed bug Observed behavior contradicts documented or intended behavior labels Feb 26, 2025
@Vexu Vexu added this to the 0.15.0 milestone Feb 26, 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

2 participants