From c42763f8cc9223fc43ac3478a5f15d4bd9f438e4 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 24 Nov 2021 14:47:33 -0700 Subject: [PATCH] AstGen: use reachableExpr for return operand Related: #9630 --- lib/std/math/ln.zig | 2 +- lib/std/math/log.zig | 2 +- lib/std/math/log10.zig | 2 +- lib/std/math/log2.zig | 2 +- lib/std/math/sqrt.zig | 2 +- src/AstGen.zig | 2 +- test/compile_errors.zig | 9 +++++++++ 7 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/std/math/ln.zig b/lib/std/math/ln.zig index d2a5ae807e..bb352cd6e1 100644 --- a/lib/std/math/ln.zig +++ b/lib/std/math/ln.zig @@ -32,7 +32,7 @@ pub fn ln(x: anytype) @TypeOf(x) { return @as(comptime_int, math.floor(ln_64(@as(f64, x)))); }, .Int => |IntType| switch (IntType.signedness) { - .signed => return @compileError("ln not implemented for signed integers"), + .signed => @compileError("ln not implemented for signed integers"), .unsigned => return @as(T, math.floor(ln_64(@as(f64, x)))), }, else => @compileError("ln not implemented for " ++ @typeName(T)), diff --git a/lib/std/math/log.zig b/lib/std/math/log.zig index cab652c620..6336726b39 100644 --- a/lib/std/math/log.zig +++ b/lib/std/math/log.zig @@ -29,7 +29,7 @@ pub fn log(comptime T: type, base: T, x: T) T { // TODO implement integer log without using float math .Int => |IntType| switch (IntType.signedness) { - .signed => return @compileError("log not implemented for signed integers"), + .signed => @compileError("log not implemented for signed integers"), .unsigned => return @floatToInt(T, math.floor(math.ln(@intToFloat(f64, x)) / math.ln(float_base))), }, diff --git a/lib/std/math/log10.zig b/lib/std/math/log10.zig index 19602fb4a2..84eced85f0 100644 --- a/lib/std/math/log10.zig +++ b/lib/std/math/log10.zig @@ -33,7 +33,7 @@ pub fn log10(x: anytype) @TypeOf(x) { return @as(comptime_int, math.floor(log10_64(@as(f64, x)))); }, .Int => |IntType| switch (IntType.signedness) { - .signed => return @compileError("log10 not implemented for signed integers"), + .signed => @compileError("log10 not implemented for signed integers"), .unsigned => return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x)))), }, else => @compileError("log10 not implemented for " ++ @typeName(T)), diff --git a/lib/std/math/log2.zig b/lib/std/math/log2.zig index fca941c49a..556c16f5cf 100644 --- a/lib/std/math/log2.zig +++ b/lib/std/math/log2.zig @@ -39,7 +39,7 @@ pub fn log2(x: anytype) @TypeOf(x) { return result; }, .Int => |IntType| switch (IntType.signedness) { - .signed => return @compileError("log2 not implemented for signed integers"), + .signed => @compileError("log2 not implemented for signed integers"), .unsigned => return math.log2_int(T, x), }, else => @compileError("log2 not implemented for " ++ @typeName(T)), diff --git a/lib/std/math/sqrt.zig b/lib/std/math/sqrt.zig index d54063dcf6..871cc58e47 100644 --- a/lib/std/math/sqrt.zig +++ b/lib/std/math/sqrt.zig @@ -26,7 +26,7 @@ pub fn sqrt(x: anytype) Sqrt(@TypeOf(x)) { return @as(T, sqrt_int(u128, x)); }, .Int => |IntType| switch (IntType.signedness) { - .signed => return @compileError("sqrt not implemented for signed integers"), + .signed => @compileError("sqrt not implemented for signed integers"), .unsigned => return sqrt_int(T, x), }, else => @compileError("sqrt not implemented for " ++ @typeName(T)), diff --git a/src/AstGen.zig b/src/AstGen.zig index 7132dc07ef..ae66cae662 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -5963,7 +5963,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref } else .{ .ty = try gz.addNodeExtended(.ret_type, node), }; - const operand = try expr(gz, scope, rl, operand_node); + const operand = try reachableExpr(gz, scope, rl, operand_node, node); switch (nodeMayEvalToError(tree, operand_node)) { .never => { diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 6240fae587..1a3e81e176 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -4999,6 +4999,15 @@ pub fn addCases(ctx: *TestContext) !void { "tmp.zig:2:5: note: control flow is diverted here", }); + ctx.objErrStage1("unreachable code - return return", + \\export fn a() i32 { + \\ return return 1; + \\} + , &[_][]const u8{ + "tmp.zig:2:5: error: unreachable code", + "tmp.zig:2:12: note: control flow is diverted here", + }); + ctx.objErrStage1("bad import", \\const bogus = @import("bogus-does-not-exist.zig",); , &[_][]const u8{