Skip to content

Commit c42763f

Browse files
committed
AstGen: use reachableExpr for return operand
Related: #9630
1 parent 57e1f6a commit c42763f

File tree

7 files changed

+15
-6
lines changed

7 files changed

+15
-6
lines changed

lib/std/math/ln.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn ln(x: anytype) @TypeOf(x) {
3232
return @as(comptime_int, math.floor(ln_64(@as(f64, x))));
3333
},
3434
.Int => |IntType| switch (IntType.signedness) {
35-
.signed => return @compileError("ln not implemented for signed integers"),
35+
.signed => @compileError("ln not implemented for signed integers"),
3636
.unsigned => return @as(T, math.floor(ln_64(@as(f64, x)))),
3737
},
3838
else => @compileError("ln not implemented for " ++ @typeName(T)),

lib/std/math/log.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn log(comptime T: type, base: T, x: T) T {
2929

3030
// TODO implement integer log without using float math
3131
.Int => |IntType| switch (IntType.signedness) {
32-
.signed => return @compileError("log not implemented for signed integers"),
32+
.signed => @compileError("log not implemented for signed integers"),
3333
.unsigned => return @floatToInt(T, math.floor(math.ln(@intToFloat(f64, x)) / math.ln(float_base))),
3434
},
3535

lib/std/math/log10.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn log10(x: anytype) @TypeOf(x) {
3333
return @as(comptime_int, math.floor(log10_64(@as(f64, x))));
3434
},
3535
.Int => |IntType| switch (IntType.signedness) {
36-
.signed => return @compileError("log10 not implemented for signed integers"),
36+
.signed => @compileError("log10 not implemented for signed integers"),
3737
.unsigned => return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x)))),
3838
},
3939
else => @compileError("log10 not implemented for " ++ @typeName(T)),

lib/std/math/log2.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn log2(x: anytype) @TypeOf(x) {
3939
return result;
4040
},
4141
.Int => |IntType| switch (IntType.signedness) {
42-
.signed => return @compileError("log2 not implemented for signed integers"),
42+
.signed => @compileError("log2 not implemented for signed integers"),
4343
.unsigned => return math.log2_int(T, x),
4444
},
4545
else => @compileError("log2 not implemented for " ++ @typeName(T)),

lib/std/math/sqrt.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn sqrt(x: anytype) Sqrt(@TypeOf(x)) {
2626
return @as(T, sqrt_int(u128, x));
2727
},
2828
.Int => |IntType| switch (IntType.signedness) {
29-
.signed => return @compileError("sqrt not implemented for signed integers"),
29+
.signed => @compileError("sqrt not implemented for signed integers"),
3030
.unsigned => return sqrt_int(T, x),
3131
},
3232
else => @compileError("sqrt not implemented for " ++ @typeName(T)),

src/AstGen.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5963,7 +5963,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref
59635963
} else .{
59645964
.ty = try gz.addNodeExtended(.ret_type, node),
59655965
};
5966-
const operand = try expr(gz, scope, rl, operand_node);
5966+
const operand = try reachableExpr(gz, scope, rl, operand_node, node);
59675967

59685968
switch (nodeMayEvalToError(tree, operand_node)) {
59695969
.never => {

test/compile_errors.zig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4999,6 +4999,15 @@ pub fn addCases(ctx: *TestContext) !void {
49994999
"tmp.zig:2:5: note: control flow is diverted here",
50005000
});
50015001

5002+
ctx.objErrStage1("unreachable code - return return",
5003+
\\export fn a() i32 {
5004+
\\ return return 1;
5005+
\\}
5006+
, &[_][]const u8{
5007+
"tmp.zig:2:5: error: unreachable code",
5008+
"tmp.zig:2:12: note: control flow is diverted here",
5009+
});
5010+
50025011
ctx.objErrStage1("bad import",
50035012
\\const bogus = @import("bogus-does-not-exist.zig",);
50045013
, &[_][]const u8{

0 commit comments

Comments
 (0)