mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 07:32:44 +00:00
parent
57e1f6a89f
commit
c42763f8cc
@ -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)),
|
||||
|
@ -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))),
|
||||
},
|
||||
|
||||
|
@ -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)),
|
||||
|
@ -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)),
|
||||
|
@ -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)),
|
||||
|
@ -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 => {
|
||||
|
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user