Misleading error message when attempting to perform comptime
dereference to pointer whose type doesn't have a well-defined layout when the real pointer value has another type
#22613
Labels
error message
This issue points out an error message that is unhelpful and should be improved.
Milestone
Zig Version
0.14.0-dev.2922+f77e1b862
Steps to Reproduce and Observed Output
Currently, the Zig compiler emits a poor-quality error message for the following code:
The real problem is that
&"foobar"
has a type of*const *const [6:0]u8
and that a*const [6:0]u8
can't be coerced into a[]const u8
through a pointer dereference.Expected Output
Something like the following:
Of course, the exact error message depends on how type punning at
comptime
gets implemented (see #9646 for an example). Under that proposal, I'm pretty sure this would be illegal type punning.Alternatively, I suppose that implicit pointer-to-array to slice coercions like this could be allowed in some way, which would make the above example compile successfully, but that's a topic for another issue.
The text was updated successfully, but these errors were encountered: