Sema: disallow @intFromPtr to accept comptime-only types - #17540
Conversation
|
It looks like anytype parameters are treated as comptime-only under any conditions. @Vexu , is it a bug? If so, I could open an issue and try to fix one. |
|
No, this just has the same bug that you fixed for |
AFAICT that's about something else. Currently, it seems backends (or at least LLVM) just lower these values as references to zero-bit types (so give them an arbitrary "fake address"), which is an entirely useless and unintuitive behavior. |
andrewrk
left a comment
There was a problem hiding this comment.
Thanks! After a minor rewording of the error message, this is ready to land.
| const pointee_ty = ptr_ty.childType(mod); | ||
| if (try sema.typeRequiresComptime(ptr_ty)) { | ||
| const msg = msg: { | ||
| const msg = try sema.errMsg(block, ptr_src, "cannot accept pointer to comptime-only type '{}'", .{pointee_ty.fmt(mod)}); |
There was a problem hiding this comment.
| const msg = try sema.errMsg(block, ptr_src, "cannot accept pointer to comptime-only type '{}'", .{pointee_ty.fmt(mod)}); | |
| const msg = try sema.errMsg(block, ptr_src, "comptime-only type '{}' has no pointer address", .{pointee_ty.fmt(mod)}); |
There was a problem hiding this comment.
@andrewrk Is it worth mentioning this in the langref?
It would make a lot more sense if we prevented it from accepting pointers to comptime-only types.