diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-11-29 14:53:54 +0200 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-11-29 21:44:08 +0200 |
| commit | 17ff002bc0ac55850e647fc3a70a43d1d874f6ab (patch) | |
| tree | 700cbc62d0ec95cc2b660cb8d33ab0970e39c9f8 /lib/std | |
| parent | 6337c04244d9c27cc6535340347d4c127f4742eb (diff) | |
| download | zig-17ff002bc0ac55850e647fc3a70a43d1d874f6ab.tar.gz zig-17ff002bc0ac55850e647fc3a70a43d1d874f6ab.zip | |
Sema: improve safety panic for access of inactive union field
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/builtin.zig | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 09833988ae..fcdf43bd31 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -868,6 +868,11 @@ pub fn panicStartGreaterThanEnd(start: usize, end: usize) noreturn { std.debug.panicExtra(null, @returnAddress(), "start index {d} is larger than end index {d}", .{ start, end }); } +pub fn panicInactiveUnionField(active: anytype, wanted: @TypeOf(active)) noreturn { + @setCold(true); + std.debug.panicExtra(null, @returnAddress(), "access of union field '{s}' while field '{s}' is active", .{ @tagName(wanted), @tagName(active) }); +} + pub const panic_messages = struct { pub const unreach = "reached unreachable code"; pub const unwrap_null = "attempt to use null value"; |
