mirror of
https://github.com/ziglang/zig.git
synced 2026-02-17 14:59:14 +00:00
Sema: add missing error for runtime @ptrFromInt to comptime-only type
Closes #20083
This commit is contained in:
parent
2cf8e73781
commit
17a0458e53
@ -22722,7 +22722,16 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
|
||||
.storage = .{ .elems = new_elems },
|
||||
} }));
|
||||
}
|
||||
if (try sema.typeRequiresComptime(ptr_ty)) {
|
||||
return sema.failWithOwnedErrorMsg(block, msg: {
|
||||
const msg = try sema.errMsg(block, src, "pointer to comptime-only type '{}' must be comptime-known, but operand is runtime-known", .{ptr_ty.fmt(mod)});
|
||||
errdefer msg.destroy(sema.gpa);
|
||||
|
||||
const src_decl = mod.declPtr(block.src_decl);
|
||||
try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), ptr_ty);
|
||||
break :msg msg;
|
||||
});
|
||||
}
|
||||
try sema.requireRuntimeBlock(block, src, operand_src);
|
||||
if (!is_vector) {
|
||||
if (block.wantSafety() and (try sema.typeHasRuntimeBits(elem_ty) or elem_ty.zigTypeTag(mod) == .Fn)) {
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
const GuSettings = struct {
|
||||
fin: ?fn (c_int) callconv(.C) void,
|
||||
};
|
||||
pub export fn callbackFin(id: c_int, arg: ?*anyopaque) void {
|
||||
const settings: ?*GuSettings = @as(?*GuSettings, @ptrFromInt(@intFromPtr(arg)));
|
||||
if (settings.?.fin != null) {
|
||||
settings.?.fin.?(id & 0xffff);
|
||||
}
|
||||
}
|
||||
|
||||
// error
|
||||
// target=native
|
||||
//
|
||||
// :5:54: error: pointer to comptime-only type '?*tmp.GuSettings' must be comptime-known, but operand is runtime-known
|
||||
// :2:10: note: struct requires comptime because of this field
|
||||
// :2:10: note: use '*const fn (c_int) callconv(.C) void' for a function pointer type
|
||||
Loading…
x
Reference in New Issue
Block a user