authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-06-28 17:17:26-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-02 13:26:50-07:00
log22b20f20b66a0225fe1d57ab8773ac066c205bdd
treeb85456a881e28631d4844dd7ea1ae384f776be33
parent7f5560689aeb0e2ab84c5e3dc48f84247bd5bdc3

AstGen: fix missing compile error for unreachable `@TypeOf` argument


2 files changed, 5 insertions(+), 4 deletions(-)

doc/langref.html.in+2-2
......@@ -4228,8 +4228,8 @@ test "type of unreachable" {
42284228 comptime {
42294229 // The type of unreachable is noreturn.
42304230
4231 // However this assertion will still fail because
4232 // evaluating unreachable at compile-time is a compile error.
4231 // However this assertion will still fail to compile because
4232 // unreachable expressions are compile errors.
42334233
42344234 assert(@TypeOf(unreachable) == noreturn);
42354235 }
src/AstGen.zig+3-2
......@@ -6786,13 +6786,14 @@ fn typeOf(
67866786 return gz.astgen.failNode(node, "expected at least 1 argument, found 0", .{});
67876787 }
67886788 if (params.len == 1) {
6789 const result = try gz.addUnNode(.typeof, try expr(gz, scope, .none, params[0]), node);
6789 const expr_result = try reachableExpr(gz, scope, .none, params[0], node);
6790 const result = try gz.addUnNode(.typeof, expr_result, node);
67906791 return rvalue(gz, rl, result, node);
67916792 }
67926793 const arena = gz.astgen.arena;
67936794 var items = try arena.alloc(Zir.Inst.Ref, params.len);
67946795 for (params) |param, param_i| {
6795 items[param_i] = try expr(gz, scope, .none, param);
6796 items[param_i] = try reachableExpr(gz, scope, .none, param, node);
67966797 }
67976798
67986799 const result = try gz.addExtendedMultiOp(.typeof_peer, node, items);