diff --git a/doc/langref.html.in b/doc/langref.html.in
index 667b4cd2a7..31de76359e 100644
--- a/doc/langref.html.in
+++ b/doc/langref.html.in
@@ -4228,8 +4228,8 @@ test "type of unreachable" {
comptime {
// The type of unreachable is noreturn.
- // However this assertion will still fail because
- // evaluating unreachable at compile-time is a compile error.
+ // However this assertion will still fail to compile because
+ // unreachable expressions are compile errors.
assert(@TypeOf(unreachable) == noreturn);
}
diff --git a/src/AstGen.zig b/src/AstGen.zig
index 15b5b88d9a..7e599da78b 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -6786,13 +6786,14 @@ fn typeOf(
return gz.astgen.failNode(node, "expected at least 1 argument, found 0", .{});
}
if (params.len == 1) {
- const result = try gz.addUnNode(.typeof, try expr(gz, scope, .none, params[0]), node);
+ const expr_result = try reachableExpr(gz, scope, .none, params[0], node);
+ const result = try gz.addUnNode(.typeof, expr_result, node);
return rvalue(gz, rl, result, node);
}
const arena = gz.astgen.arena;
var items = try arena.alloc(Zir.Inst.Ref, params.len);
for (params) |param, param_i| {
- items[param_i] = try expr(gz, scope, .none, param);
+ items[param_i] = try reachableExpr(gz, scope, .none, param, node);
}
const result = try gz.addExtendedMultiOp(.typeof_peer, node, items);