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" {...@@ -4228,8 +4228,8 @@ test "type of unreachable" {
4228 comptime {4228 comptime {
4229 // The type of unreachable is noreturn.4229 // The type of unreachable is noreturn.
42304230
4231 // However this assertion will still fail because4231 // However this assertion will still fail to compile because
4232 // evaluating unreachable at compile-time is a compile error.4232 // unreachable expressions are compile errors.
42334233
4234 assert(@TypeOf(unreachable) == noreturn);4234 assert(@TypeOf(unreachable) == noreturn);
4235 }4235 }
src/AstGen.zig+3-2
...@@ -6786,13 +6786,14 @@ fn typeOf(...@@ -6786,13 +6786,14 @@ fn typeOf(
6786 return gz.astgen.failNode(node, "expected at least 1 argument, found 0", .{});6786 return gz.astgen.failNode(node, "expected at least 1 argument, found 0", .{});
6787 }6787 }
6788 if (params.len == 1) {6788 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);
6790 return rvalue(gz, rl, result, node);6791 return rvalue(gz, rl, result, node);
6791 }6792 }
6792 const arena = gz.astgen.arena;6793 const arena = gz.astgen.arena;
6793 var items = try arena.alloc(Zir.Inst.Ref, params.len);6794 var items = try arena.alloc(Zir.Inst.Ref, params.len);
6794 for (params) |param, param_i| {6795 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);
6796 }6797 }
67976798
6798 const result = try gz.addExtendedMultiOp(.typeof_peer, node, items);6799 const result = try gz.addExtendedMultiOp(.typeof_peer, node, items);