Files
zig/test/cases/compile_errors/bad_panic_generic_signature.zig
mlugg 83991efe10 compiler: yet more panic handler changes
* `std.builtin.Panic` -> `std.builtin.panic`, because it is a namespace.
* `root.Panic` -> `root.panic` for the same reason. There are type
  checks so that we still allow the legacy `pub fn panic` strategy in
  the 0.14.0 release.
* `std.debug.SimplePanic` -> `std.debug.simple_panic`, same reason.
* `std.debug.NoPanic` -> `std.debug.no_panic`, same reason.
* `std.debug.FormattedPanic` is now a function `std.debug.FullPanic`
  which takes as input a `panicFn` and returns a namespace with all the
  panic functions. This handles the incredibly common case of just
  wanting to override how the message is printed, whilst keeping nice
  formatted panics.
* Remove `std.builtin.panic.messages`; now, every safety panic has its
  own function. This reduces binary bloat, as calls to these functions
  no longer need to prepare any arguments (aside from the error return
  trace).
* Remove some legacy declarations, since a zig1.wasm update has
  happened. Most of these were related to the panic handler, but a quick
  grep for "zig1" brought up a couple more results too.

Also, add some missing type checks to Sema.

Resolves: #22584

formatted -> full
2025-01-24 19:29:51 +00:00

42 lines
1.9 KiB
Zig

const simple_panic = std.debug.simple_panic;
pub const panic = struct {
pub fn sentinelMismatch() void {} // invalid
pub const call = simple_panic.call;
pub const unwrapError = simple_panic.unwrapError;
pub const outOfBounds = simple_panic.outOfBounds;
pub const startGreaterThanEnd = simple_panic.startGreaterThanEnd;
pub const inactiveUnionField = simple_panic.inactiveUnionField;
pub const reachedUnreachable = simple_panic.reachedUnreachable;
pub const unwrapNull = simple_panic.unwrapNull;
pub const castToNull = simple_panic.castToNull;
pub const incorrectAlignment = simple_panic.incorrectAlignment;
pub const invalidErrorCode = simple_panic.invalidErrorCode;
pub const castTruncatedData = simple_panic.castTruncatedData;
pub const negativeToUnsigned = simple_panic.negativeToUnsigned;
pub const integerOverflow = simple_panic.integerOverflow;
pub const shlOverflow = simple_panic.shlOverflow;
pub const shrOverflow = simple_panic.shrOverflow;
pub const divideByZero = simple_panic.divideByZero;
pub const exactDivisionRemainder = simple_panic.exactDivisionRemainder;
pub const integerPartOutOfBounds = simple_panic.integerPartOutOfBounds;
pub const corruptSwitch = simple_panic.corruptSwitch;
pub const shiftRhsTooBig = simple_panic.shiftRhsTooBig;
pub const invalidEnumValue = simple_panic.invalidEnumValue;
pub const forLenMismatch = simple_panic.forLenMismatch;
pub const memcpyLenMismatch = simple_panic.memcpyLenMismatch;
pub const memcpyAlias = simple_panic.memcpyAlias;
pub const noreturnReturned = simple_panic.noreturnReturned;
};
export fn foo(arr: *const [2]u8) void {
@setRuntimeSafety(true);
_ = arr[0..1 :0];
}
const std = @import("std");
// error
//
// :3:9: error: expected type 'fn (anytype, anytype) noreturn', found 'fn () void'
// :3:9: note: non-generic function cannot cast into a generic function