Skip to content

Commit

Permalink
AstGen: use reachableExpr for return operand
Browse files Browse the repository at this point in the history
Related: #9630
  • Loading branch information
andrewrk committed Nov 24, 2021
1 parent 57e1f6a commit c42763f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/std/math/ln.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
2 changes: 1 addition & 1 deletion lib/std/math/log.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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))),
},

Expand Down
2 changes: 1 addition & 1 deletion lib/std/math/log10.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
2 changes: 1 addition & 1 deletion lib/std/math/log2.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
2 changes: 1 addition & 1 deletion lib/std/math/sqrt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
2 changes: 1 addition & 1 deletion src/AstGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
9 changes: 9 additions & 0 deletions test/compile_errors.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit c42763f

Please sign in to comment.