Commit c42763f8cc

Andrew Kelley <andrew@ziglang.org>
2021-11-24 22:47:33
AstGen: use reachableExpr for return operand
Related: #9630
1 parent 57e1f6a
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)),
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))),
         },
 
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)),
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)),
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)),
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 => {
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{