diff --git a/src/Sema.zig b/src/Sema.zig index 773b7aa66c..2b8705339c 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -16492,6 +16492,9 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air const inst_data = sema.code.instructions.items(.data)[inst].un_node; const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; const ty = try sema.resolveType(block, operand_src, inst_data.operand); + if (ty.isNoReturn()) { + return sema.fail(block, operand_src, "no align available for type '{}'", .{ty.fmt(sema.mod)}); + } const target = sema.mod.getTarget(); const val = try ty.lazyAbiAlignment(target, sema.arena); if (val.tag() == .lazy_align) { diff --git a/test/cases/compile_errors/alignOf_bad_type.zig b/test/cases/compile_errors/alignOf_bad_type.zig new file mode 100644 index 0000000000..5408c21314 --- /dev/null +++ b/test/cases/compile_errors/alignOf_bad_type.zig @@ -0,0 +1,9 @@ +export fn entry() usize { + return @alignOf(noreturn); +} + +// error +// backend=stage2 +// target=native +// +// :2:21: error: no align available for type 'noreturn'