Replace @typeOf with @TypeOf in all zig source

This change was mostly made with `zig fmt` and this also modified some whitespace. Note that in some files, `zig fmt` produced incorrect code, so the change was made manually.
This commit is contained in:
Robin Voetter 2019-12-09 21:56:19 +01:00 committed by Andrew Kelley
parent f0ee0688f2
commit 4b4fbe3887
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
125 changed files with 508 additions and 504 deletions

View File

@ -40,7 +40,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {
.allocator = allocator, .allocator = allocator,
}; };
} }
/// Initialize with capacity to hold at least num elements. /// Initialize with capacity to hold at least num elements.
/// Deinitialize with `deinit` or use `toOwnedSlice`. /// Deinitialize with `deinit` or use `toOwnedSlice`.
pub fn initCapacity(allocator: *Allocator, num: usize) !Self { pub fn initCapacity(allocator: *Allocator, num: usize) !Self {

View File

@ -106,7 +106,7 @@ pub fn Queue(comptime T: type) type {
pub fn dump(self: *Self) void { pub fn dump(self: *Self) void {
var stderr_file = std.io.getStdErr() catch return; var stderr_file = std.io.getStdErr() catch return;
const stderr = &stderr_file.outStream().stream; const stderr = &stderr_file.outStream().stream;
const Error = @typeInfo(@typeOf(stderr)).Pointer.child.Error; const Error = @typeInfo(@TypeOf(stderr)).Pointer.child.Error;
self.dumpToStream(Error, stderr) catch return; self.dumpToStream(Error, stderr) catch return;
} }

View File

@ -9,7 +9,7 @@ const expect = std.testing.expect;
pub fn Stack(comptime T: type) type { pub fn Stack(comptime T: type) type {
return struct { return struct {
root: ?*Node, root: ?*Node,
lock: @typeOf(lock_init), lock: @TypeOf(lock_init),
const lock_init = if (builtin.single_threaded) {} else @as(u8, 0); const lock_init = if (builtin.single_threaded) {} else @as(u8, 0);

View File

@ -1290,7 +1290,7 @@ pub const DwarfInfo = struct {
try di.dwarf_seekable_stream.seekTo(this_unit_offset); try di.dwarf_seekable_stream.seekTo(this_unit_offset);
var is_64: bool = undefined; var is_64: bool = undefined;
const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64); const unit_length = try readInitialLength(@TypeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
if (unit_length == 0) return; if (unit_length == 0) return;
const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4)); const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));
@ -1392,7 +1392,7 @@ pub const DwarfInfo = struct {
try di.dwarf_seekable_stream.seekTo(this_unit_offset); try di.dwarf_seekable_stream.seekTo(this_unit_offset);
var is_64: bool = undefined; var is_64: bool = undefined;
const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64); const unit_length = try readInitialLength(@TypeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
if (unit_length == 0) return; if (unit_length == 0) return;
const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4)); const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));
@ -1551,7 +1551,7 @@ pub const DwarfInfo = struct {
try di.dwarf_seekable_stream.seekTo(di.debug_line.offset + line_info_offset); try di.dwarf_seekable_stream.seekTo(di.debug_line.offset + line_info_offset);
var is_64: bool = undefined; var is_64: bool = undefined;
const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64); const unit_length = try readInitialLength(@TypeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
if (unit_length == 0) { if (unit_length == 0) {
return error.MissingDebugInfo; return error.MissingDebugInfo;
} }
@ -2080,7 +2080,7 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64
DW.FORM_strp => FormValue{ .StrPtr = try parseFormValueDwarfOffsetSize(in_stream, is_64) }, DW.FORM_strp => FormValue{ .StrPtr = try parseFormValueDwarfOffsetSize(in_stream, is_64) },
DW.FORM_indirect => { DW.FORM_indirect => {
const child_form_id = try noasync leb.readULEB128(u64, in_stream); const child_form_id = try noasync leb.readULEB128(u64, in_stream);
const F = @typeOf(async parseFormValue(allocator, in_stream, child_form_id, is_64)); const F = @TypeOf(async parseFormValue(allocator, in_stream, child_form_id, is_64));
var frame = try allocator.create(F); var frame = try allocator.create(F);
defer allocator.destroy(frame); defer allocator.destroy(frame);
return await @asyncCall(frame, {}, parseFormValue, allocator, in_stream, child_form_id, is_64); return await @asyncCall(frame, {}, parseFormValue, allocator, in_stream, child_form_id, is_64);

View File

@ -61,7 +61,7 @@ pub fn Group(comptime ReturnType: type) type {
/// `func` must be async and have return type `ReturnType`. /// `func` must be async and have return type `ReturnType`.
/// Thread-safe. /// Thread-safe.
pub fn call(self: *Self, comptime func: var, args: var) error{OutOfMemory}!void { pub fn call(self: *Self, comptime func: var, args: var) error{OutOfMemory}!void {
var frame = try self.allocator.create(@typeOf(@call(.{ .modifier = .async_kw }, func, args))); var frame = try self.allocator.create(@TypeOf(@call(.{ .modifier = .async_kw }, func, args)));
errdefer self.allocator.destroy(frame); errdefer self.allocator.destroy(frame);
const node = try self.allocator.create(AllocStack.Node); const node = try self.allocator.create(AllocStack.Node);
errdefer self.allocator.destroy(node); errdefer self.allocator.destroy(node);

View File

@ -42,7 +42,7 @@ pub const Loop = struct {
}, },
else => {}, else => {},
}; };
pub const Overlapped = @typeOf(overlapped_init); pub const Overlapped = @TypeOf(overlapped_init);
pub const Id = enum { pub const Id = enum {
Basic, Basic,

View File

@ -89,7 +89,7 @@ fn peekIsAlign(comptime fmt: []const u8) bool {
pub fn format( pub fn format(
context: var, context: var,
comptime Errors: type, comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void, output: fn (@TypeOf(context), []const u8) Errors!void,
comptime fmt: []const u8, comptime fmt: []const u8,
args: var, args: var,
) Errors!void { ) Errors!void {
@ -320,17 +320,17 @@ pub fn formatType(
options: FormatOptions, options: FormatOptions,
context: var, context: var,
comptime Errors: type, comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void, output: fn (@TypeOf(context), []const u8) Errors!void,
max_depth: usize, max_depth: usize,
) Errors!void { ) Errors!void {
if (comptime std.mem.eql(u8, fmt, "*")) { if (comptime std.mem.eql(u8, fmt, "*")) {
try output(context, @typeName(@typeOf(value).Child)); try output(context, @typeName(@TypeOf(value).Child));
try output(context, "@"); try output(context, "@");
try formatInt(@ptrToInt(value), 16, false, FormatOptions{}, context, Errors, output); try formatInt(@ptrToInt(value), 16, false, FormatOptions{}, context, Errors, output);
return; return;
} }
const T = @typeOf(value); const T = @TypeOf(value);
switch (@typeInfo(T)) { switch (@typeInfo(T)) {
.ComptimeInt, .Int, .Float => { .ComptimeInt, .Int, .Float => {
return formatValue(value, fmt, options, context, Errors, output); return formatValue(value, fmt, options, context, Errors, output);
@ -478,7 +478,7 @@ fn formatValue(
options: FormatOptions, options: FormatOptions,
context: var, context: var,
comptime Errors: type, comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void, output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void { ) Errors!void {
if (comptime std.mem.eql(u8, fmt, "B")) { if (comptime std.mem.eql(u8, fmt, "B")) {
return formatBytes(value, options, 1000, context, Errors, output); return formatBytes(value, options, 1000, context, Errors, output);
@ -486,7 +486,7 @@ fn formatValue(
return formatBytes(value, options, 1024, context, Errors, output); return formatBytes(value, options, 1024, context, Errors, output);
} }
const T = @typeOf(value); const T = @TypeOf(value);
switch (@typeId(T)) { switch (@typeId(T)) {
.Float => return formatFloatValue(value, fmt, options, context, Errors, output), .Float => return formatFloatValue(value, fmt, options, context, Errors, output),
.Int, .ComptimeInt => return formatIntValue(value, fmt, options, context, Errors, output), .Int, .ComptimeInt => return formatIntValue(value, fmt, options, context, Errors, output),
@ -500,12 +500,12 @@ pub fn formatIntValue(
options: FormatOptions, options: FormatOptions,
context: var, context: var,
comptime Errors: type, comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void, output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void { ) Errors!void {
comptime var radix = 10; comptime var radix = 10;
comptime var uppercase = false; comptime var uppercase = false;
const int_value = if (@typeOf(value) == comptime_int) blk: { const int_value = if (@TypeOf(value) == comptime_int) blk: {
const Int = math.IntFittingRange(value, value); const Int = math.IntFittingRange(value, value);
break :blk @as(Int, value); break :blk @as(Int, value);
} else } else
@ -515,7 +515,7 @@ pub fn formatIntValue(
radix = 10; radix = 10;
uppercase = false; uppercase = false;
} else if (comptime std.mem.eql(u8, fmt, "c")) { } else if (comptime std.mem.eql(u8, fmt, "c")) {
if (@typeOf(int_value).bit_count <= 8) { if (@TypeOf(int_value).bit_count <= 8) {
return formatAsciiChar(@as(u8, int_value), options, context, Errors, output); return formatAsciiChar(@as(u8, int_value), options, context, Errors, output);
} else { } else {
@compileError("Cannot print integer that is larger than 8 bits as a ascii"); @compileError("Cannot print integer that is larger than 8 bits as a ascii");
@ -542,7 +542,7 @@ fn formatFloatValue(
options: FormatOptions, options: FormatOptions,
context: var, context: var,
comptime Errors: type, comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void, output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void { ) Errors!void {
if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "e")) { if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "e")) {
return formatFloatScientific(value, options, context, Errors, output); return formatFloatScientific(value, options, context, Errors, output);
@ -559,7 +559,7 @@ pub fn formatText(
options: FormatOptions, options: FormatOptions,
context: var, context: var,
comptime Errors: type, comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void, output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void { ) Errors!void {
if (fmt.len == 0) { if (fmt.len == 0) {
return output(context, bytes); return output(context, bytes);
@ -580,7 +580,7 @@ pub fn formatAsciiChar(
options: FormatOptions, options: FormatOptions,
context: var, context: var,
comptime Errors: type, comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void, output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void { ) Errors!void {
return output(context, @as(*const [1]u8, &c)[0..]); return output(context, @as(*const [1]u8, &c)[0..]);
} }
@ -590,7 +590,7 @@ pub fn formatBuf(
options: FormatOptions, options: FormatOptions,
context: var, context: var,
comptime Errors: type, comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void, output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void { ) Errors!void {
try output(context, buf); try output(context, buf);
@ -610,7 +610,7 @@ pub fn formatFloatScientific(
options: FormatOptions, options: FormatOptions,
context: var, context: var,
comptime Errors: type, comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void, output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void { ) Errors!void {
var x = @floatCast(f64, value); var x = @floatCast(f64, value);
@ -672,7 +672,7 @@ pub fn formatFloatScientific(
try output(context, float_decimal.digits[0..1]); try output(context, float_decimal.digits[0..1]);
try output(context, "."); try output(context, ".");
if (float_decimal.digits.len > 1) { if (float_decimal.digits.len > 1) {
const num_digits = if (@typeOf(value) == f32) math.min(@as(usize, 9), float_decimal.digits.len) else float_decimal.digits.len; const num_digits = if (@TypeOf(value) == f32) math.min(@as(usize, 9), float_decimal.digits.len) else float_decimal.digits.len;
try output(context, float_decimal.digits[1..num_digits]); try output(context, float_decimal.digits[1..num_digits]);
} else { } else {
@ -705,7 +705,7 @@ pub fn formatFloatDecimal(
options: FormatOptions, options: FormatOptions,
context: var, context: var,
comptime Errors: type, comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void, output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void { ) Errors!void {
var x = @as(f64, value); var x = @as(f64, value);
@ -851,7 +851,7 @@ pub fn formatBytes(
comptime radix: usize, comptime radix: usize,
context: var, context: var,
comptime Errors: type, comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void, output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void { ) Errors!void {
if (value == 0) { if (value == 0) {
return output(context, "0B"); return output(context, "0B");
@ -892,15 +892,15 @@ pub fn formatInt(
options: FormatOptions, options: FormatOptions,
context: var, context: var,
comptime Errors: type, comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void, output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void { ) Errors!void {
const int_value = if (@typeOf(value) == comptime_int) blk: { const int_value = if (@TypeOf(value) == comptime_int) blk: {
const Int = math.IntFittingRange(value, value); const Int = math.IntFittingRange(value, value);
break :blk @as(Int, value); break :blk @as(Int, value);
} else } else
value; value;
if (@typeOf(int_value).is_signed) { if (@TypeOf(int_value).is_signed) {
return formatIntSigned(int_value, base, uppercase, options, context, Errors, output); return formatIntSigned(int_value, base, uppercase, options, context, Errors, output);
} else { } else {
return formatIntUnsigned(int_value, base, uppercase, options, context, Errors, output); return formatIntUnsigned(int_value, base, uppercase, options, context, Errors, output);
@ -914,7 +914,7 @@ fn formatIntSigned(
options: FormatOptions, options: FormatOptions,
context: var, context: var,
comptime Errors: type, comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void, output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void { ) Errors!void {
const new_options = FormatOptions{ const new_options = FormatOptions{
.width = if (options.width) |w| (if (w == 0) 0 else w - 1) else null, .width = if (options.width) |w| (if (w == 0) 0 else w - 1) else null,
@ -922,7 +922,7 @@ fn formatIntSigned(
.fill = options.fill, .fill = options.fill,
}; };
const uint = @IntType(false, @typeOf(value).bit_count); const uint = @IntType(false, @TypeOf(value).bit_count);
if (value < 0) { if (value < 0) {
const minus_sign: u8 = '-'; const minus_sign: u8 = '-';
try output(context, @as(*const [1]u8, &minus_sign)[0..]); try output(context, @as(*const [1]u8, &minus_sign)[0..]);
@ -945,12 +945,12 @@ fn formatIntUnsigned(
options: FormatOptions, options: FormatOptions,
context: var, context: var,
comptime Errors: type, comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void, output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void { ) Errors!void {
assert(base >= 2); assert(base >= 2);
var buf: [math.max(@typeOf(value).bit_count, 1)]u8 = undefined; var buf: [math.max(@TypeOf(value).bit_count, 1)]u8 = undefined;
const min_int_bits = comptime math.max(@typeOf(value).bit_count, @typeOf(base).bit_count); const min_int_bits = comptime math.max(@TypeOf(value).bit_count, @TypeOf(base).bit_count);
const MinInt = @IntType(@typeOf(value).is_signed, min_int_bits); const MinInt = @IntType(@TypeOf(value).is_signed, min_int_bits);
var a: MinInt = value; var a: MinInt = value;
var index: usize = buf.len; var index: usize = buf.len;
@ -1420,7 +1420,7 @@ test "custom" {
options: FormatOptions, options: FormatOptions,
context: var, context: var,
comptime Errors: type, comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void, output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void { ) Errors!void {
if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "p")) { if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "p")) {
return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y }); return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y });
@ -1610,7 +1610,7 @@ test "formatIntValue with comptime_int" {
const value: comptime_int = 123456789123456789; const value: comptime_int = 123456789123456789;
var buf = try std.Buffer.init(std.debug.global_allocator, ""); var buf = try std.Buffer.init(std.debug.global_allocator, "");
try formatIntValue(value, "", FormatOptions{}, &buf, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append); try formatIntValue(value, "", FormatOptions{}, &buf, @TypeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append);
std.testing.expect(mem.eql(u8, buf.toSlice(), "123456789123456789")); std.testing.expect(mem.eql(u8, buf.toSlice(), "123456789123456789"));
} }
@ -1626,7 +1626,7 @@ test "formatType max_depth" {
options: FormatOptions, options: FormatOptions,
context: var, context: var,
comptime Errors: type, comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void, output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void { ) Errors!void {
if (fmt.len == 0) { if (fmt.len == 0) {
return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y }); return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y });
@ -1664,19 +1664,19 @@ test "formatType max_depth" {
inst.tu.ptr = &inst.tu; inst.tu.ptr = &inst.tu;
var buf0 = try std.Buffer.init(std.debug.global_allocator, ""); var buf0 = try std.Buffer.init(std.debug.global_allocator, "");
try formatType(inst, "", FormatOptions{}, &buf0, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 0); try formatType(inst, "", FormatOptions{}, &buf0, @TypeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 0);
std.testing.expect(mem.eql(u8, buf0.toSlice(), "S{ ... }")); std.testing.expect(mem.eql(u8, buf0.toSlice(), "S{ ... }"));
var buf1 = try std.Buffer.init(std.debug.global_allocator, ""); var buf1 = try std.Buffer.init(std.debug.global_allocator, "");
try formatType(inst, "", FormatOptions{}, &buf1, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 1); try formatType(inst, "", FormatOptions{}, &buf1, @TypeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 1);
std.testing.expect(mem.eql(u8, buf1.toSlice(), "S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }")); std.testing.expect(mem.eql(u8, buf1.toSlice(), "S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }"));
var buf2 = try std.Buffer.init(std.debug.global_allocator, ""); var buf2 = try std.Buffer.init(std.debug.global_allocator, "");
try formatType(inst, "", FormatOptions{}, &buf2, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 2); try formatType(inst, "", FormatOptions{}, &buf2, @TypeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 2);
std.testing.expect(mem.eql(u8, buf2.toSlice(), "S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }")); std.testing.expect(mem.eql(u8, buf2.toSlice(), "S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }"));
var buf3 = try std.Buffer.init(std.debug.global_allocator, ""); var buf3 = try std.Buffer.init(std.debug.global_allocator, "");
try formatType(inst, "", FormatOptions{}, &buf3, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 3); try formatType(inst, "", FormatOptions{}, &buf3, @TypeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 3);
std.testing.expect(mem.eql(u8, buf3.toSlice(), "S{ .a = S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ .ptr = TU{ ... } } }, .e = E.Two, .vec = (10.200,2.220) }")); std.testing.expect(mem.eql(u8, buf3.toSlice(), "S{ .a = S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ .ptr = TU{ ... } } }, .e = E.Two, .vec = (10.200,2.220) }"));
} }

View File

@ -22,7 +22,7 @@ pub const HashStrategy = enum {
/// Helper function to hash a pointer and mutate the strategy if needed. /// Helper function to hash a pointer and mutate the strategy if needed.
pub fn hashPointer(hasher: var, key: var, comptime strat: HashStrategy) void { pub fn hashPointer(hasher: var, key: var, comptime strat: HashStrategy) void {
const info = @typeInfo(@typeOf(key)); const info = @typeInfo(@TypeOf(key));
switch (info.Pointer.size) { switch (info.Pointer.size) {
builtin.TypeInfo.Pointer.Size.One => switch (strat) { builtin.TypeInfo.Pointer.Size.One => switch (strat) {
@ -74,7 +74,7 @@ pub fn hashArray(hasher: var, key: var, comptime strat: HashStrategy) void {
/// Provides generic hashing for any eligible type. /// Provides generic hashing for any eligible type.
/// Strategy is provided to determine if pointers should be followed or not. /// Strategy is provided to determine if pointers should be followed or not.
pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void { pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void {
const Key = @typeOf(key); const Key = @TypeOf(key);
switch (@typeInfo(Key)) { switch (@typeInfo(Key)) {
.NoReturn, .NoReturn,
.Opaque, .Opaque,
@ -164,7 +164,7 @@ pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void {
/// Only hashes `key` itself, pointers are not followed. /// Only hashes `key` itself, pointers are not followed.
/// Slices are rejected to avoid ambiguity on the user's intention. /// Slices are rejected to avoid ambiguity on the user's intention.
pub fn autoHash(hasher: var, key: var) void { pub fn autoHash(hasher: var, key: var) void {
const Key = @typeOf(key); const Key = @TypeOf(key);
if (comptime meta.trait.isSlice(Key)) { if (comptime meta.trait.isSlice(Key)) {
comptime assert(@hasDecl(std, "StringHashMap")); // detect when the following message needs updated comptime assert(@hasDecl(std, "StringHashMap")); // detect when the following message needs updated
const extra_help = if (Key == []const u8) const extra_help = if (Key == []const u8)

View File

@ -360,9 +360,9 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
var hashes: [hashbytes * 256]u8 = undefined; var hashes: [hashbytes * 256]u8 = undefined;
var final: [hashbytes]u8 = undefined; var final: [hashbytes]u8 = undefined;
@memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@typeOf(key))); @memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@TypeOf(key)));
@memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@typeOf(hashes))); @memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@TypeOf(hashes)));
@memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@typeOf(final))); @memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@TypeOf(final)));
var i: u32 = 0; var i: u32 = 0;
while (i < 256) : (i += 1) { while (i < 256) : (i += 1) {
@ -370,7 +370,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
var h = hash_fn(key[0..i], 256 - i); var h = hash_fn(key[0..i], 256 - i);
if (builtin.endian == builtin.Endian.Big) if (builtin.endian == builtin.Endian.Big)
h = @byteSwap(@typeOf(h), h); h = @byteSwap(@TypeOf(h), h);
@memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes); @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
} }

View File

@ -285,9 +285,9 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
var hashes: [hashbytes * 256]u8 = undefined; var hashes: [hashbytes * 256]u8 = undefined;
var final: [hashbytes]u8 = undefined; var final: [hashbytes]u8 = undefined;
@memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@typeOf(key))); @memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@TypeOf(key)));
@memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@typeOf(hashes))); @memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@TypeOf(hashes)));
@memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@typeOf(final))); @memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@TypeOf(final)));
var i: u32 = 0; var i: u32 = 0;
while (i < 256) : (i += 1) { while (i < 256) : (i += 1) {
@ -295,7 +295,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
var h = hash_fn(key[0..i], 256 - i); var h = hash_fn(key[0..i], 256 - i);
if (builtin.endian == builtin.Endian.Big) if (builtin.endian == builtin.Endian.Big)
h = @byteSwap(@typeOf(h), h); h = @byteSwap(@TypeOf(h), h);
@memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes); @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
} }

View File

@ -367,7 +367,7 @@ pub const Headers = struct {
options: std.fmt.FormatOptions, options: std.fmt.FormatOptions,
context: var, context: var,
comptime Errors: type, comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void, output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void { ) Errors!void {
var it = self.iterator(); var it = self.iterator();
while (it.next()) |entry| { while (it.next()) |entry| {

View File

@ -663,7 +663,7 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type {
pub fn writeBits(self: *Self, value: var, bits: usize) Error!void { pub fn writeBits(self: *Self, value: var, bits: usize) Error!void {
if (bits == 0) return; if (bits == 0) return;
const U = @typeOf(value); const U = @TypeOf(value);
comptime assert(trait.isUnsignedInt(U)); comptime assert(trait.isUnsignedInt(U));
//by extending the buffer to a minimum of u8 we can cover a number of edge cases //by extending the buffer to a minimum of u8 we can cover a number of edge cases
@ -962,7 +962,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
/// Deserializes data into the type pointed to by `ptr` /// Deserializes data into the type pointed to by `ptr`
pub fn deserializeInto(self: *Self, ptr: var) !void { pub fn deserializeInto(self: *Self, ptr: var) !void {
const T = @typeOf(ptr); const T = @TypeOf(ptr);
comptime assert(trait.is(builtin.TypeId.Pointer)(T)); comptime assert(trait.is(builtin.TypeId.Pointer)(T));
if (comptime trait.isSlice(T) or comptime trait.isPtrTo(builtin.TypeId.Array)(T)) { if (comptime trait.isSlice(T) or comptime trait.isPtrTo(builtin.TypeId.Array)(T)) {
@ -1091,7 +1091,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
} }
fn serializeInt(self: *Self, value: var) Error!void { fn serializeInt(self: *Self, value: var) Error!void {
const T = @typeOf(value); const T = @TypeOf(value);
comptime assert(trait.is(builtin.TypeId.Int)(T) or trait.is(builtin.TypeId.Float)(T)); comptime assert(trait.is(builtin.TypeId.Int)(T) or trait.is(builtin.TypeId.Float)(T));
const t_bit_count = comptime meta.bitCount(T); const t_bit_count = comptime meta.bitCount(T);
@ -1123,7 +1123,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
/// Serializes the passed value into the stream /// Serializes the passed value into the stream
pub fn serialize(self: *Self, value: var) Error!void { pub fn serialize(self: *Self, value: var) Error!void {
const T = comptime @typeOf(value); const T = comptime @TypeOf(value);
if (comptime trait.isIndexable(T)) { if (comptime trait.isIndexable(T)) {
for (value) |v| for (value) |v|

View File

@ -1038,7 +1038,7 @@ pub const Value = union(enum) {
} }
pub fn dumpStream(self: @This(), stream: var, comptime max_depth: usize) !void { pub fn dumpStream(self: @This(), stream: var, comptime max_depth: usize) !void {
var w = std.json.WriteStream(@typeOf(stream).Child, max_depth).init(stream); var w = std.json.WriteStream(@TypeOf(stream).Child, max_depth).init(stream);
w.newline = ""; w.newline = "";
w.one_indent = ""; w.one_indent = "";
w.space = ""; w.space = "";
@ -1048,7 +1048,7 @@ pub const Value = union(enum) {
pub fn dumpStreamIndent(self: @This(), comptime indent: usize, stream: var, comptime max_depth: usize) !void { pub fn dumpStreamIndent(self: @This(), comptime indent: usize, stream: var, comptime max_depth: usize) !void {
var one_indent = " " ** indent; var one_indent = " " ** indent;
var w = std.json.WriteStream(@typeOf(stream).Child, max_depth).init(stream); var w = std.json.WriteStream(@TypeOf(stream).Child, max_depth).init(stream);
w.one_indent = one_indent; w.one_indent = one_indent;
try w.emitJson(self); try w.emitJson(self);
} }
@ -1338,7 +1338,7 @@ test "write json then parse it" {
var slice_out_stream = std.io.SliceOutStream.init(&out_buffer); var slice_out_stream = std.io.SliceOutStream.init(&out_buffer);
const out_stream = &slice_out_stream.stream; const out_stream = &slice_out_stream.stream;
var jw = WriteStream(@typeOf(out_stream).Child, 4).init(out_stream); var jw = WriteStream(@TypeOf(out_stream).Child, 4).init(out_stream);
try jw.beginObject(); try jw.beginObject();

View File

@ -155,7 +155,7 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
value: var, value: var,
) !void { ) !void {
assert(self.state[self.state_index] == State.Value); assert(self.state[self.state_index] == State.Value);
switch (@typeInfo(@typeOf(value))) { switch (@typeInfo(@TypeOf(value))) {
.Int => |info| { .Int => |info| {
if (info.bits < 53) { if (info.bits < 53) {
try self.stream.print("{}", .{value}); try self.stream.print("{}", .{value});
@ -257,7 +257,7 @@ test "json write stream" {
var mem_buf: [1024 * 10]u8 = undefined; var mem_buf: [1024 * 10]u8 = undefined;
const allocator = &std.heap.FixedBufferAllocator.init(&mem_buf).allocator; const allocator = &std.heap.FixedBufferAllocator.init(&mem_buf).allocator;
var w = std.json.WriteStream(@typeOf(out).Child, 10).init(out); var w = std.json.WriteStream(@TypeOf(out).Child, 10).init(out);
try w.emitJson(try getJson(allocator)); try w.emitJson(try getJson(allocator));
const result = slice_stream.getWritten(); const result = slice_stream.getWritten();

View File

@ -95,7 +95,7 @@ pub fn approxEq(comptime T: type, x: T, y: T, epsilon: T) bool {
// TODO: Hide the following in an internal module. // TODO: Hide the following in an internal module.
pub fn forceEval(value: var) void { pub fn forceEval(value: var) void {
const T = @typeOf(value); const T = @TypeOf(value);
switch (T) { switch (T) {
f16 => { f16 => {
var x: f16 = undefined; var x: f16 = undefined;
@ -239,13 +239,13 @@ pub fn Min(comptime A: type, comptime B: type) type {
}, },
else => {}, else => {},
} }
return @typeOf(@as(A, 0) + @as(B, 0)); return @TypeOf(@as(A, 0) + @as(B, 0));
} }
/// Returns the smaller number. When one of the parameter's type's full range fits in the other, /// Returns the smaller number. When one of the parameter's type's full range fits in the other,
/// the return type is the smaller type. /// the return type is the smaller type.
pub fn min(x: var, y: var) Min(@typeOf(x), @typeOf(y)) { pub fn min(x: var, y: var) Min(@TypeOf(x), @TypeOf(y)) {
const Result = Min(@typeOf(x), @typeOf(y)); const Result = Min(@TypeOf(x), @TypeOf(y));
if (x < y) { if (x < y) {
// TODO Zig should allow this as an implicit cast because x is immutable and in this // TODO Zig should allow this as an implicit cast because x is immutable and in this
// scope it is known to fit in the return type. // scope it is known to fit in the return type.
@ -269,33 +269,33 @@ test "math.min" {
var a: u16 = 999; var a: u16 = 999;
var b: u32 = 10; var b: u32 = 10;
var result = min(a, b); var result = min(a, b);
testing.expect(@typeOf(result) == u16); testing.expect(@TypeOf(result) == u16);
testing.expect(result == 10); testing.expect(result == 10);
} }
{ {
var a: f64 = 10.34; var a: f64 = 10.34;
var b: f32 = 999.12; var b: f32 = 999.12;
var result = min(a, b); var result = min(a, b);
testing.expect(@typeOf(result) == f64); testing.expect(@TypeOf(result) == f64);
testing.expect(result == 10.34); testing.expect(result == 10.34);
} }
{ {
var a: i8 = -127; var a: i8 = -127;
var b: i16 = -200; var b: i16 = -200;
var result = min(a, b); var result = min(a, b);
testing.expect(@typeOf(result) == i16); testing.expect(@TypeOf(result) == i16);
testing.expect(result == -200); testing.expect(result == -200);
} }
{ {
const a = 10.34; const a = 10.34;
var b: f32 = 999.12; var b: f32 = 999.12;
var result = min(a, b); var result = min(a, b);
testing.expect(@typeOf(result) == f32); testing.expect(@TypeOf(result) == f32);
testing.expect(result == 10.34); testing.expect(result == 10.34);
} }
} }
pub fn max(x: var, y: var) @typeOf(x + y) { pub fn max(x: var, y: var) @TypeOf(x + y) {
return if (x > y) x else y; return if (x > y) x else y;
} }
@ -318,8 +318,8 @@ pub fn sub(comptime T: type, a: T, b: T) (error{Overflow}!T) {
return if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer; return if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer;
} }
pub fn negate(x: var) !@typeOf(x) { pub fn negate(x: var) !@TypeOf(x) {
return sub(@typeOf(x), 0, x); return sub(@TypeOf(x), 0, x);
} }
pub fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) !T { pub fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) !T {
@ -333,7 +333,7 @@ pub fn shl(comptime T: type, a: T, shift_amt: var) T {
const abs_shift_amt = absCast(shift_amt); const abs_shift_amt = absCast(shift_amt);
const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else @intCast(Log2Int(T), abs_shift_amt); const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else @intCast(Log2Int(T), abs_shift_amt);
if (@typeOf(shift_amt) == comptime_int or @typeOf(shift_amt).is_signed) { if (@TypeOf(shift_amt) == comptime_int or @TypeOf(shift_amt).is_signed) {
if (shift_amt < 0) { if (shift_amt < 0) {
return a >> casted_shift_amt; return a >> casted_shift_amt;
} }
@ -359,7 +359,7 @@ pub fn shr(comptime T: type, a: T, shift_amt: var) T {
const abs_shift_amt = absCast(shift_amt); const abs_shift_amt = absCast(shift_amt);
const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else @intCast(Log2Int(T), abs_shift_amt); const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else @intCast(Log2Int(T), abs_shift_amt);
if (@typeOf(shift_amt) == comptime_int or @typeOf(shift_amt).is_signed) { if (@TypeOf(shift_amt) == comptime_int or @TypeOf(shift_amt).is_signed) {
if (shift_amt >= 0) { if (shift_amt >= 0) {
return a >> casted_shift_amt; return a >> casted_shift_amt;
} else { } else {
@ -505,12 +505,12 @@ fn testOverflow() void {
testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000); testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);
} }
pub fn absInt(x: var) !@typeOf(x) { pub fn absInt(x: var) !@TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt
comptime assert(T.is_signed); // must pass a signed integer to absInt comptime assert(T.is_signed); // must pass a signed integer to absInt
if (x == minInt(@typeOf(x))) { if (x == minInt(@TypeOf(x))) {
return error.Overflow; return error.Overflow;
} else { } else {
@setRuntimeSafety(false); @setRuntimeSafety(false);
@ -654,16 +654,16 @@ fn testRem() void {
/// Returns the absolute value of the integer parameter. /// Returns the absolute value of the integer parameter.
/// Result is an unsigned integer. /// Result is an unsigned integer.
pub fn absCast(x: var) t: { pub fn absCast(x: var) t: {
if (@typeOf(x) == comptime_int) { if (@TypeOf(x) == comptime_int) {
break :t comptime_int; break :t comptime_int;
} else { } else {
break :t @IntType(false, @typeOf(x).bit_count); break :t @IntType(false, @TypeOf(x).bit_count);
} }
} { } {
if (@typeOf(x) == comptime_int) { if (@TypeOf(x) == comptime_int) {
return if (x < 0) -x else x; return if (x < 0) -x else x;
} }
const uint = @IntType(false, @typeOf(x).bit_count); const uint = @IntType(false, @TypeOf(x).bit_count);
if (x >= 0) return @intCast(uint, x); if (x >= 0) return @intCast(uint, x);
return @intCast(uint, -(x + 1)) + 1; return @intCast(uint, -(x + 1)) + 1;
@ -671,23 +671,23 @@ pub fn absCast(x: var) t: {
test "math.absCast" { test "math.absCast" {
testing.expect(absCast(@as(i32, -999)) == 999); testing.expect(absCast(@as(i32, -999)) == 999);
testing.expect(@typeOf(absCast(@as(i32, -999))) == u32); testing.expect(@TypeOf(absCast(@as(i32, -999))) == u32);
testing.expect(absCast(@as(i32, 999)) == 999); testing.expect(absCast(@as(i32, 999)) == 999);
testing.expect(@typeOf(absCast(@as(i32, 999))) == u32); testing.expect(@TypeOf(absCast(@as(i32, 999))) == u32);
testing.expect(absCast(@as(i32, minInt(i32))) == -minInt(i32)); testing.expect(absCast(@as(i32, minInt(i32))) == -minInt(i32));
testing.expect(@typeOf(absCast(@as(i32, minInt(i32)))) == u32); testing.expect(@TypeOf(absCast(@as(i32, minInt(i32)))) == u32);
testing.expect(absCast(-999) == 999); testing.expect(absCast(-999) == 999);
} }
/// Returns the negation of the integer parameter. /// Returns the negation of the integer parameter.
/// Result is a signed integer. /// Result is a signed integer.
pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) { pub fn negateCast(x: var) !@IntType(true, @TypeOf(x).bit_count) {
if (@typeOf(x).is_signed) return negate(x); if (@TypeOf(x).is_signed) return negate(x);
const int = @IntType(true, @typeOf(x).bit_count); const int = @IntType(true, @TypeOf(x).bit_count);
if (x > -minInt(int)) return error.Overflow; if (x > -minInt(int)) return error.Overflow;
if (x == -minInt(int)) return minInt(int); if (x == -minInt(int)) return minInt(int);
@ -697,10 +697,10 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) {
test "math.negateCast" { test "math.negateCast" {
testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999); testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);
testing.expect(@typeOf(negateCast(@as(u32, 999)) catch unreachable) == i32); testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);
testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32)); testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32));
testing.expect(@typeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32); testing.expect(@TypeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32);
testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10))); testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10)));
} }
@ -709,10 +709,10 @@ test "math.negateCast" {
/// return an error. /// return an error.
pub fn cast(comptime T: type, x: var) (error{Overflow}!T) { pub fn cast(comptime T: type, x: var) (error{Overflow}!T) {
comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer
comptime assert(@typeId(@typeOf(x)) == builtin.TypeId.Int); // must pass an integer comptime assert(@typeId(@TypeOf(x)) == builtin.TypeId.Int); // must pass an integer
if (maxInt(@typeOf(x)) > maxInt(T) and x > maxInt(T)) { if (maxInt(@TypeOf(x)) > maxInt(T) and x > maxInt(T)) {
return error.Overflow; return error.Overflow;
} else if (minInt(@typeOf(x)) < minInt(T) and x < minInt(T)) { } else if (minInt(@TypeOf(x)) < minInt(T) and x < minInt(T)) {
return error.Overflow; return error.Overflow;
} else { } else {
return @intCast(T, x); return @intCast(T, x);
@ -726,13 +726,13 @@ test "math.cast" {
testing.expectError(error.Overflow, cast(u64, @as(i8, -1))); testing.expectError(error.Overflow, cast(u64, @as(i8, -1)));
testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255)); testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));
testing.expect(@typeOf(try cast(u8, @as(u32, 255))) == u8); testing.expect(@TypeOf(try cast(u8, @as(u32, 255))) == u8);
} }
pub const AlignCastError = error{UnalignedMemory}; pub const AlignCastError = error{UnalignedMemory};
/// Align cast a pointer but return an error if it's the wrong alignment /// Align cast a pointer but return an error if it's the wrong alignment
pub fn alignCast(comptime alignment: u29, ptr: var) AlignCastError!@typeOf(@alignCast(alignment, ptr)) { pub fn alignCast(comptime alignment: u29, ptr: var) AlignCastError!@TypeOf(@alignCast(alignment, ptr)) {
const addr = @ptrToInt(ptr); const addr = @ptrToInt(ptr);
if (addr % alignment != 0) { if (addr % alignment != 0) {
return error.UnalignedMemory; return error.UnalignedMemory;
@ -858,7 +858,7 @@ test "std.math.log2_int_ceil" {
} }
pub fn lossyCast(comptime T: type, value: var) T { pub fn lossyCast(comptime T: type, value: var) T {
switch (@typeInfo(@typeOf(value))) { switch (@typeInfo(@TypeOf(value))) {
builtin.TypeId.Int => return @intToFloat(T, value), builtin.TypeId.Int => return @intToFloat(T, value),
builtin.TypeId.Float => return @floatCast(T, value), builtin.TypeId.Float => return @floatCast(T, value),
builtin.TypeId.ComptimeInt => return @as(T, value), builtin.TypeId.ComptimeInt => return @as(T, value),

View File

@ -12,8 +12,8 @@ const expect = std.testing.expect;
/// ///
/// Special cases: /// Special cases:
/// - acos(x) = nan if x < -1 or x > 1 /// - acos(x) = nan if x < -1 or x > 1
pub fn acos(x: var) @typeOf(x) { pub fn acos(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => acos32(x), f32 => acos32(x),
f64 => acos64(x), f64 => acos64(x),

View File

@ -14,8 +14,8 @@ const expect = std.testing.expect;
/// Special cases: /// Special cases:
/// - acosh(x) = snan if x < 1 /// - acosh(x) = snan if x < 1
/// - acosh(nan) = nan /// - acosh(nan) = nan
pub fn acosh(x: var) @typeOf(x) { pub fn acosh(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => acosh32(x), f32 => acosh32(x),
f64 => acosh64(x), f64 => acosh64(x),

View File

@ -13,8 +13,8 @@ const expect = std.testing.expect;
/// Special Cases: /// Special Cases:
/// - asin(+-0) = +-0 /// - asin(+-0) = +-0
/// - asin(x) = nan if x < -1 or x > 1 /// - asin(x) = nan if x < -1 or x > 1
pub fn asin(x: var) @typeOf(x) { pub fn asin(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => asin32(x), f32 => asin32(x),
f64 => asin64(x), f64 => asin64(x),

View File

@ -15,8 +15,8 @@ const maxInt = std.math.maxInt;
/// - asinh(+-0) = +-0 /// - asinh(+-0) = +-0
/// - asinh(+-inf) = +-inf /// - asinh(+-inf) = +-inf
/// - asinh(nan) = nan /// - asinh(nan) = nan
pub fn asinh(x: var) @typeOf(x) { pub fn asinh(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => asinh32(x), f32 => asinh32(x),
f64 => asinh64(x), f64 => asinh64(x),

View File

@ -13,8 +13,8 @@ const expect = std.testing.expect;
/// Special Cases: /// Special Cases:
/// - atan(+-0) = +-0 /// - atan(+-0) = +-0
/// - atan(+-inf) = +-pi/2 /// - atan(+-inf) = +-pi/2
pub fn atan(x: var) @typeOf(x) { pub fn atan(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => atan32(x), f32 => atan32(x),
f64 => atan64(x), f64 => atan64(x),

View File

@ -15,8 +15,8 @@ const maxInt = std.math.maxInt;
/// - atanh(+-1) = +-inf with signal /// - atanh(+-1) = +-inf with signal
/// - atanh(x) = nan if |x| > 1 with signal /// - atanh(x) = nan if |x| > 1 with signal
/// - atanh(nan) = nan /// - atanh(nan) = nan
pub fn atanh(x: var) @typeOf(x) { pub fn atanh(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => atanh_32(x), f32 => atanh_32(x),
f64 => atanh_64(x), f64 => atanh_64(x),

View File

@ -268,7 +268,7 @@ pub const Int = struct {
/// Sets an Int to value. Value must be an primitive integer type. /// Sets an Int to value. Value must be an primitive integer type.
pub fn set(self: *Int, value: var) Allocator.Error!void { pub fn set(self: *Int, value: var) Allocator.Error!void {
self.assertWritable(); self.assertWritable();
const T = @typeOf(value); const T = @TypeOf(value);
switch (@typeInfo(T)) { switch (@typeInfo(T)) {
TypeId.Int => |info| { TypeId.Int => |info| {
@ -522,7 +522,7 @@ pub const Int = struct {
options: std.fmt.FormatOptions, options: std.fmt.FormatOptions,
context: var, context: var,
comptime FmtError: type, comptime FmtError: type,
output: fn (@typeOf(context), []const u8) FmtError!void, output: fn (@TypeOf(context), []const u8) FmtError!void,
) FmtError!void { ) FmtError!void {
self.assertWritable(); self.assertWritable();
// TODO look at fmt and support other bases // TODO look at fmt and support other bases

View File

@ -14,8 +14,8 @@ const expect = std.testing.expect;
/// - cbrt(+-0) = +-0 /// - cbrt(+-0) = +-0
/// - cbrt(+-inf) = +-inf /// - cbrt(+-inf) = +-inf
/// - cbrt(nan) = nan /// - cbrt(nan) = nan
pub fn cbrt(x: var) @typeOf(x) { pub fn cbrt(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => cbrt32(x), f32 => cbrt32(x),
f64 => cbrt64(x), f64 => cbrt64(x),

View File

@ -15,8 +15,8 @@ const expect = std.testing.expect;
/// - ceil(+-0) = +-0 /// - ceil(+-0) = +-0
/// - ceil(+-inf) = +-inf /// - ceil(+-inf) = +-inf
/// - ceil(nan) = nan /// - ceil(nan) = nan
pub fn ceil(x: var) @typeOf(x) { pub fn ceil(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => ceil32(x), f32 => ceil32(x),
f64 => ceil64(x), f64 => ceil64(x),

View File

@ -5,8 +5,8 @@ const cmath = math.complex;
const Complex = cmath.Complex; const Complex = cmath.Complex;
/// Returns the absolute value (modulus) of z. /// Returns the absolute value (modulus) of z.
pub fn abs(z: var) @typeOf(z.re) { pub fn abs(z: var) @TypeOf(z.re) {
const T = @typeOf(z.re); const T = @TypeOf(z.re);
return math.hypot(T, z.re, z.im); return math.hypot(T, z.re, z.im);
} }

View File

@ -5,8 +5,8 @@ const cmath = math.complex;
const Complex = cmath.Complex; const Complex = cmath.Complex;
/// Returns the arc-cosine of z. /// Returns the arc-cosine of z.
pub fn acos(z: var) Complex(@typeOf(z.re)) { pub fn acos(z: var) Complex(@TypeOf(z.re)) {
const T = @typeOf(z.re); const T = @TypeOf(z.re);
const q = cmath.asin(z); const q = cmath.asin(z);
return Complex(T).new(@as(T, math.pi) / 2 - q.re, -q.im); return Complex(T).new(@as(T, math.pi) / 2 - q.re, -q.im);
} }

View File

@ -5,8 +5,8 @@ const cmath = math.complex;
const Complex = cmath.Complex; const Complex = cmath.Complex;
/// Returns the hyperbolic arc-cosine of z. /// Returns the hyperbolic arc-cosine of z.
pub fn acosh(z: var) Complex(@typeOf(z.re)) { pub fn acosh(z: var) Complex(@TypeOf(z.re)) {
const T = @typeOf(z.re); const T = @TypeOf(z.re);
const q = cmath.acos(z); const q = cmath.acos(z);
return Complex(T).new(-q.im, q.re); return Complex(T).new(-q.im, q.re);
} }

View File

@ -5,8 +5,8 @@ const cmath = math.complex;
const Complex = cmath.Complex; const Complex = cmath.Complex;
/// Returns the angular component (in radians) of z. /// Returns the angular component (in radians) of z.
pub fn arg(z: var) @typeOf(z.re) { pub fn arg(z: var) @TypeOf(z.re) {
const T = @typeOf(z.re); const T = @TypeOf(z.re);
return math.atan2(T, z.im, z.re); return math.atan2(T, z.im, z.re);
} }

View File

@ -5,8 +5,8 @@ const cmath = math.complex;
const Complex = cmath.Complex; const Complex = cmath.Complex;
// Returns the arc-sine of z. // Returns the arc-sine of z.
pub fn asin(z: var) Complex(@typeOf(z.re)) { pub fn asin(z: var) Complex(@TypeOf(z.re)) {
const T = @typeOf(z.re); const T = @TypeOf(z.re);
const x = z.re; const x = z.re;
const y = z.im; const y = z.im;

View File

@ -5,8 +5,8 @@ const cmath = math.complex;
const Complex = cmath.Complex; const Complex = cmath.Complex;
/// Returns the hyperbolic arc-sine of z. /// Returns the hyperbolic arc-sine of z.
pub fn asinh(z: var) Complex(@typeOf(z.re)) { pub fn asinh(z: var) Complex(@TypeOf(z.re)) {
const T = @typeOf(z.re); const T = @TypeOf(z.re);
const q = Complex(T).new(-z.im, z.re); const q = Complex(T).new(-z.im, z.re);
const r = cmath.asin(q); const r = cmath.asin(q);
return Complex(T).new(r.im, -r.re); return Complex(T).new(r.im, -r.re);

View File

@ -12,8 +12,8 @@ const cmath = math.complex;
const Complex = cmath.Complex; const Complex = cmath.Complex;
/// Returns the arc-tangent of z. /// Returns the arc-tangent of z.
pub fn atan(z: var) @typeOf(z) { pub fn atan(z: var) @TypeOf(z) {
const T = @typeOf(z.re); const T = @TypeOf(z.re);
return switch (T) { return switch (T) {
f32 => atan32(z), f32 => atan32(z),
f64 => atan64(z), f64 => atan64(z),

View File

@ -5,8 +5,8 @@ const cmath = math.complex;
const Complex = cmath.Complex; const Complex = cmath.Complex;
/// Returns the hyperbolic arc-tangent of z. /// Returns the hyperbolic arc-tangent of z.
pub fn atanh(z: var) Complex(@typeOf(z.re)) { pub fn atanh(z: var) Complex(@TypeOf(z.re)) {
const T = @typeOf(z.re); const T = @TypeOf(z.re);
const q = Complex(T).new(-z.im, z.re); const q = Complex(T).new(-z.im, z.re);
const r = cmath.atan(q); const r = cmath.atan(q);
return Complex(T).new(r.im, -r.re); return Complex(T).new(r.im, -r.re);

View File

@ -5,8 +5,8 @@ const cmath = math.complex;
const Complex = cmath.Complex; const Complex = cmath.Complex;
/// Returns the complex conjugate of z. /// Returns the complex conjugate of z.
pub fn conj(z: var) Complex(@typeOf(z.re)) { pub fn conj(z: var) Complex(@TypeOf(z.re)) {
const T = @typeOf(z.re); const T = @TypeOf(z.re);
return Complex(T).new(z.re, -z.im); return Complex(T).new(z.re, -z.im);
} }

View File

@ -5,8 +5,8 @@ const cmath = math.complex;
const Complex = cmath.Complex; const Complex = cmath.Complex;
/// Returns the cosine of z. /// Returns the cosine of z.
pub fn cos(z: var) Complex(@typeOf(z.re)) { pub fn cos(z: var) Complex(@TypeOf(z.re)) {
const T = @typeOf(z.re); const T = @TypeOf(z.re);
const p = Complex(T).new(-z.im, z.re); const p = Complex(T).new(-z.im, z.re);
return cmath.cosh(p); return cmath.cosh(p);
} }

View File

@ -14,8 +14,8 @@ const Complex = cmath.Complex;
const ldexp_cexp = @import("ldexp.zig").ldexp_cexp; const ldexp_cexp = @import("ldexp.zig").ldexp_cexp;
/// Returns the hyperbolic arc-cosine of z. /// Returns the hyperbolic arc-cosine of z.
pub fn cosh(z: var) Complex(@typeOf(z.re)) { pub fn cosh(z: var) Complex(@TypeOf(z.re)) {
const T = @typeOf(z.re); const T = @TypeOf(z.re);
return switch (T) { return switch (T) {
f32 => cosh32(z), f32 => cosh32(z),
f64 => cosh64(z), f64 => cosh64(z),

View File

@ -14,8 +14,8 @@ const Complex = cmath.Complex;
const ldexp_cexp = @import("ldexp.zig").ldexp_cexp; const ldexp_cexp = @import("ldexp.zig").ldexp_cexp;
/// Returns e raised to the power of z (e^z). /// Returns e raised to the power of z (e^z).
pub fn exp(z: var) @typeOf(z) { pub fn exp(z: var) @TypeOf(z) {
const T = @typeOf(z.re); const T = @TypeOf(z.re);
return switch (T) { return switch (T) {
f32 => exp32(z), f32 => exp32(z),

View File

@ -11,8 +11,8 @@ const cmath = math.complex;
const Complex = cmath.Complex; const Complex = cmath.Complex;
/// Returns exp(z) scaled to avoid overflow. /// Returns exp(z) scaled to avoid overflow.
pub fn ldexp_cexp(z: var, expt: i32) @typeOf(z) { pub fn ldexp_cexp(z: var, expt: i32) @TypeOf(z) {
const T = @typeOf(z.re); const T = @TypeOf(z.re);
return switch (T) { return switch (T) {
f32 => ldexp_cexp32(z, expt), f32 => ldexp_cexp32(z, expt),

View File

@ -5,8 +5,8 @@ const cmath = math.complex;
const Complex = cmath.Complex; const Complex = cmath.Complex;
/// Returns the natural logarithm of z. /// Returns the natural logarithm of z.
pub fn log(z: var) Complex(@typeOf(z.re)) { pub fn log(z: var) Complex(@TypeOf(z.re)) {
const T = @typeOf(z.re); const T = @TypeOf(z.re);
const r = cmath.abs(z); const r = cmath.abs(z);
const phi = cmath.arg(z); const phi = cmath.arg(z);

View File

@ -5,8 +5,8 @@ const cmath = math.complex;
const Complex = cmath.Complex; const Complex = cmath.Complex;
/// Returns the projection of z onto the riemann sphere. /// Returns the projection of z onto the riemann sphere.
pub fn proj(z: var) Complex(@typeOf(z.re)) { pub fn proj(z: var) Complex(@TypeOf(z.re)) {
const T = @typeOf(z.re); const T = @TypeOf(z.re);
if (math.isInf(z.re) or math.isInf(z.im)) { if (math.isInf(z.re) or math.isInf(z.im)) {
return Complex(T).new(math.inf(T), math.copysign(T, 0, z.re)); return Complex(T).new(math.inf(T), math.copysign(T, 0, z.re));

View File

@ -5,8 +5,8 @@ const cmath = math.complex;
const Complex = cmath.Complex; const Complex = cmath.Complex;
/// Returns the sine of z. /// Returns the sine of z.
pub fn sin(z: var) Complex(@typeOf(z.re)) { pub fn sin(z: var) Complex(@TypeOf(z.re)) {
const T = @typeOf(z.re); const T = @TypeOf(z.re);
const p = Complex(T).new(-z.im, z.re); const p = Complex(T).new(-z.im, z.re);
const q = cmath.sinh(p); const q = cmath.sinh(p);
return Complex(T).new(q.im, -q.re); return Complex(T).new(q.im, -q.re);

View File

@ -14,8 +14,8 @@ const Complex = cmath.Complex;
const ldexp_cexp = @import("ldexp.zig").ldexp_cexp; const ldexp_cexp = @import("ldexp.zig").ldexp_cexp;
/// Returns the hyperbolic sine of z. /// Returns the hyperbolic sine of z.
pub fn sinh(z: var) @typeOf(z) { pub fn sinh(z: var) @TypeOf(z) {
const T = @typeOf(z.re); const T = @TypeOf(z.re);
return switch (T) { return switch (T) {
f32 => sinh32(z), f32 => sinh32(z),
f64 => sinh64(z), f64 => sinh64(z),

View File

@ -12,8 +12,8 @@ const Complex = cmath.Complex;
/// Returns the square root of z. The real and imaginary parts of the result have the same sign /// Returns the square root of z. The real and imaginary parts of the result have the same sign
/// as the imaginary part of z. /// as the imaginary part of z.
pub fn sqrt(z: var) @typeOf(z) { pub fn sqrt(z: var) @TypeOf(z) {
const T = @typeOf(z.re); const T = @TypeOf(z.re);
return switch (T) { return switch (T) {
f32 => sqrt32(z), f32 => sqrt32(z),

View File

@ -5,8 +5,8 @@ const cmath = math.complex;
const Complex = cmath.Complex; const Complex = cmath.Complex;
/// Returns the tanget of z. /// Returns the tanget of z.
pub fn tan(z: var) Complex(@typeOf(z.re)) { pub fn tan(z: var) Complex(@TypeOf(z.re)) {
const T = @typeOf(z.re); const T = @TypeOf(z.re);
const q = Complex(T).new(-z.im, z.re); const q = Complex(T).new(-z.im, z.re);
const r = cmath.tanh(q); const r = cmath.tanh(q);
return Complex(T).new(r.im, -r.re); return Complex(T).new(r.im, -r.re);

View File

@ -12,8 +12,8 @@ const cmath = math.complex;
const Complex = cmath.Complex; const Complex = cmath.Complex;
/// Returns the hyperbolic tangent of z. /// Returns the hyperbolic tangent of z.
pub fn tanh(z: var) @typeOf(z) { pub fn tanh(z: var) @TypeOf(z) {
const T = @typeOf(z.re); const T = @TypeOf(z.re);
return switch (T) { return switch (T) {
f32 => tanh32(z), f32 => tanh32(z),
f64 => tanh64(z), f64 => tanh64(z),

View File

@ -13,8 +13,8 @@ const expect = std.testing.expect;
/// Special Cases: /// Special Cases:
/// - cos(+-inf) = nan /// - cos(+-inf) = nan
/// - cos(nan) = nan /// - cos(nan) = nan
pub fn cos(x: var) @typeOf(x) { pub fn cos(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => cos_(f32, x), f32 => cos_(f32, x),
f64 => cos_(f64, x), f64 => cos_(f64, x),

View File

@ -17,8 +17,8 @@ const maxInt = std.math.maxInt;
/// - cosh(+-0) = 1 /// - cosh(+-0) = 1
/// - cosh(+-inf) = +inf /// - cosh(+-inf) = +inf
/// - cosh(nan) = nan /// - cosh(nan) = nan
pub fn cosh(x: var) @typeOf(x) { pub fn cosh(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => cosh32(x), f32 => cosh32(x),
f64 => cosh64(x), f64 => cosh64(x),

View File

@ -14,8 +14,8 @@ const builtin = @import("builtin");
/// Special Cases: /// Special Cases:
/// - exp(+inf) = +inf /// - exp(+inf) = +inf
/// - exp(nan) = nan /// - exp(nan) = nan
pub fn exp(x: var) @typeOf(x) { pub fn exp(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => exp32(x), f32 => exp32(x),
f64 => exp64(x), f64 => exp64(x),

View File

@ -13,8 +13,8 @@ const expect = std.testing.expect;
/// Special Cases: /// Special Cases:
/// - exp2(+inf) = +inf /// - exp2(+inf) = +inf
/// - exp2(nan) = nan /// - exp2(nan) = nan
pub fn exp2(x: var) @typeOf(x) { pub fn exp2(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => exp2_32(x), f32 => exp2_32(x),
f64 => exp2_64(x), f64 => exp2_64(x),

View File

@ -18,8 +18,8 @@ const expect = std.testing.expect;
/// - expm1(+inf) = +inf /// - expm1(+inf) = +inf
/// - expm1(-inf) = -1 /// - expm1(-inf) = -1
/// - expm1(nan) = nan /// - expm1(nan) = nan
pub fn expm1(x: var) @typeOf(x) { pub fn expm1(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => expm1_32(x), f32 => expm1_32(x),
f64 => expm1_64(x), f64 => expm1_64(x),

View File

@ -7,8 +7,8 @@
const math = @import("../math.zig"); const math = @import("../math.zig");
/// Returns exp(x) / 2 for x >= log(maxFloat(T)). /// Returns exp(x) / 2 for x >= log(maxFloat(T)).
pub fn expo2(x: var) @typeOf(x) { pub fn expo2(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => expo2f(x), f32 => expo2f(x),
f64 => expo2d(x), f64 => expo2d(x),

View File

@ -14,8 +14,8 @@ const maxInt = std.math.maxInt;
/// Special Cases: /// Special Cases:
/// - fabs(+-inf) = +inf /// - fabs(+-inf) = +inf
/// - fabs(nan) = nan /// - fabs(nan) = nan
pub fn fabs(x: var) @typeOf(x) { pub fn fabs(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f16 => fabs16(x), f16 => fabs16(x),
f32 => fabs32(x), f32 => fabs32(x),

View File

@ -15,8 +15,8 @@ const math = std.math;
/// - floor(+-0) = +-0 /// - floor(+-0) = +-0
/// - floor(+-inf) = +-inf /// - floor(+-inf) = +-inf
/// - floor(nan) = nan /// - floor(nan) = nan
pub fn floor(x: var) @typeOf(x) { pub fn floor(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f16 => floor16(x), f16 => floor16(x),
f32 => floor32(x), f32 => floor32(x),

View File

@ -24,8 +24,8 @@ pub const frexp64_result = frexp_result(f64);
/// - frexp(+-0) = +-0, 0 /// - frexp(+-0) = +-0, 0
/// - frexp(+-inf) = +-inf, 0 /// - frexp(+-inf) = +-inf, 0
/// - frexp(nan) = nan, undefined /// - frexp(nan) = nan, undefined
pub fn frexp(x: var) frexp_result(@typeOf(x)) { pub fn frexp(x: var) frexp_result(@TypeOf(x)) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => frexp32(x), f32 => frexp32(x),
f64 => frexp64(x), f64 => frexp64(x),

View File

@ -17,7 +17,7 @@ const minInt = std.math.minInt;
/// - ilogb(0) = maxInt(i32) /// - ilogb(0) = maxInt(i32)
/// - ilogb(nan) = maxInt(i32) /// - ilogb(nan) = maxInt(i32)
pub fn ilogb(x: var) i32 { pub fn ilogb(x: var) i32 {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => ilogb32(x), f32 => ilogb32(x),
f64 => ilogb64(x), f64 => ilogb64(x),

View File

@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;
/// Returns whether x is a finite value. /// Returns whether x is a finite value.
pub fn isFinite(x: var) bool { pub fn isFinite(x: var) bool {
const T = @typeOf(x); const T = @TypeOf(x);
switch (T) { switch (T) {
f16 => { f16 => {
const bits = @bitCast(u16, x); const bits = @bitCast(u16, x);

View File

@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;
/// Returns whether x is an infinity, ignoring sign. /// Returns whether x is an infinity, ignoring sign.
pub fn isInf(x: var) bool { pub fn isInf(x: var) bool {
const T = @typeOf(x); const T = @TypeOf(x);
switch (T) { switch (T) {
f16 => { f16 => {
const bits = @bitCast(u16, x); const bits = @bitCast(u16, x);
@ -31,7 +31,7 @@ pub fn isInf(x: var) bool {
/// Returns whether x is an infinity with a positive sign. /// Returns whether x is an infinity with a positive sign.
pub fn isPositiveInf(x: var) bool { pub fn isPositiveInf(x: var) bool {
const T = @typeOf(x); const T = @TypeOf(x);
switch (T) { switch (T) {
f16 => { f16 => {
return @bitCast(u16, x) == 0x7C00; return @bitCast(u16, x) == 0x7C00;
@ -53,7 +53,7 @@ pub fn isPositiveInf(x: var) bool {
/// Returns whether x is an infinity with a negative sign. /// Returns whether x is an infinity with a negative sign.
pub fn isNegativeInf(x: var) bool { pub fn isNegativeInf(x: var) bool {
const T = @typeOf(x); const T = @TypeOf(x);
switch (T) { switch (T) {
f16 => { f16 => {
return @bitCast(u16, x) == 0xFC00; return @bitCast(u16, x) == 0xFC00;

View File

@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;
// Returns whether x has a normalized representation (i.e. integer part of mantissa is 1). // Returns whether x has a normalized representation (i.e. integer part of mantissa is 1).
pub fn isNormal(x: var) bool { pub fn isNormal(x: var) bool {
const T = @typeOf(x); const T = @TypeOf(x);
switch (T) { switch (T) {
f16 => { f16 => {
const bits = @bitCast(u16, x); const bits = @bitCast(u16, x);

View File

@ -17,11 +17,11 @@ const TypeId = builtin.TypeId;
/// - ln(0) = -inf /// - ln(0) = -inf
/// - ln(x) = nan if x < 0 /// - ln(x) = nan if x < 0
/// - ln(nan) = nan /// - ln(nan) = nan
pub fn ln(x: var) @typeOf(x) { pub fn ln(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
switch (@typeId(T)) { switch (@typeId(T)) {
TypeId.ComptimeFloat => { TypeId.ComptimeFloat => {
return @typeOf(1.0)(ln_64(x)); return @TypeOf(1.0)(ln_64(x));
}, },
TypeId.Float => { TypeId.Float => {
return switch (T) { return switch (T) {
@ -31,7 +31,7 @@ pub fn ln(x: var) @typeOf(x) {
}; };
}, },
TypeId.ComptimeInt => { TypeId.ComptimeInt => {
return @typeOf(1)(math.floor(ln_64(@as(f64, x)))); return @TypeOf(1)(math.floor(ln_64(@as(f64, x))));
}, },
TypeId.Int => { TypeId.Int => {
return @as(T, math.floor(ln_64(@as(f64, x)))); return @as(T, math.floor(ln_64(@as(f64, x))));

View File

@ -23,10 +23,10 @@ pub fn log(comptime T: type, base: T, x: T) T {
const float_base = math.lossyCast(f64, base); const float_base = math.lossyCast(f64, base);
switch (@typeId(T)) { switch (@typeId(T)) {
TypeId.ComptimeFloat => { TypeId.ComptimeFloat => {
return @typeOf(1.0)(math.ln(@as(f64, x)) / math.ln(float_base)); return @TypeOf(1.0)(math.ln(@as(f64, x)) / math.ln(float_base));
}, },
TypeId.ComptimeInt => { TypeId.ComptimeInt => {
return @typeOf(1)(math.floor(math.ln(@as(f64, x)) / math.ln(float_base))); return @TypeOf(1)(math.floor(math.ln(@as(f64, x)) / math.ln(float_base)));
}, },
builtin.TypeId.Int => { builtin.TypeId.Int => {
// TODO implement integer log without using float math // TODO implement integer log without using float math

View File

@ -18,11 +18,11 @@ const maxInt = std.math.maxInt;
/// - log10(0) = -inf /// - log10(0) = -inf
/// - log10(x) = nan if x < 0 /// - log10(x) = nan if x < 0
/// - log10(nan) = nan /// - log10(nan) = nan
pub fn log10(x: var) @typeOf(x) { pub fn log10(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
switch (@typeId(T)) { switch (@typeId(T)) {
TypeId.ComptimeFloat => { TypeId.ComptimeFloat => {
return @typeOf(1.0)(log10_64(x)); return @TypeOf(1.0)(log10_64(x));
}, },
TypeId.Float => { TypeId.Float => {
return switch (T) { return switch (T) {
@ -32,7 +32,7 @@ pub fn log10(x: var) @typeOf(x) {
}; };
}, },
TypeId.ComptimeInt => { TypeId.ComptimeInt => {
return @typeOf(1)(math.floor(log10_64(@as(f64, x)))); return @TypeOf(1)(math.floor(log10_64(@as(f64, x))));
}, },
TypeId.Int => { TypeId.Int => {
return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x)))); return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x))));

View File

@ -17,8 +17,8 @@ const expect = std.testing.expect;
/// - log1p(-1) = -inf /// - log1p(-1) = -inf
/// - log1p(x) = nan if x < -1 /// - log1p(x) = nan if x < -1
/// - log1p(nan) = nan /// - log1p(nan) = nan
pub fn log1p(x: var) @typeOf(x) { pub fn log1p(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => log1p_32(x), f32 => log1p_32(x),
f64 => log1p_64(x), f64 => log1p_64(x),

View File

@ -18,11 +18,11 @@ const maxInt = std.math.maxInt;
/// - log2(0) = -inf /// - log2(0) = -inf
/// - log2(x) = nan if x < 0 /// - log2(x) = nan if x < 0
/// - log2(nan) = nan /// - log2(nan) = nan
pub fn log2(x: var) @typeOf(x) { pub fn log2(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
switch (@typeId(T)) { switch (@typeId(T)) {
TypeId.ComptimeFloat => { TypeId.ComptimeFloat => {
return @typeOf(1.0)(log2_64(x)); return @TypeOf(1.0)(log2_64(x));
}, },
TypeId.Float => { TypeId.Float => {
return switch (T) { return switch (T) {

View File

@ -24,8 +24,8 @@ pub const modf64_result = modf_result(f64);
/// Special Cases: /// Special Cases:
/// - modf(+-inf) = +-inf, nan /// - modf(+-inf) = +-inf, nan
/// - modf(nan) = nan, nan /// - modf(nan) = nan, nan
pub fn modf(x: var) modf_result(@typeOf(x)) { pub fn modf(x: var) modf_result(@TypeOf(x)) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => modf32(x), f32 => modf32(x),
f64 => modf64(x), f64 => modf64(x),

View File

@ -15,8 +15,8 @@ const math = std.math;
/// - round(+-0) = +-0 /// - round(+-0) = +-0
/// - round(+-inf) = +-inf /// - round(+-inf) = +-inf
/// - round(nan) = nan /// - round(nan) = nan
pub fn round(x: var) @typeOf(x) { pub fn round(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => round32(x), f32 => round32(x),
f64 => round64(x), f64 => round64(x),

View File

@ -9,8 +9,8 @@ const math = std.math;
const expect = std.testing.expect; const expect = std.testing.expect;
/// Returns x * 2^n. /// Returns x * 2^n.
pub fn scalbn(x: var, n: i32) @typeOf(x) { pub fn scalbn(x: var, n: i32) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => scalbn32(x, n), f32 => scalbn32(x, n),
f64 => scalbn64(x, n), f64 => scalbn64(x, n),

View File

@ -4,7 +4,7 @@ const expect = std.testing.expect;
/// Returns whether x is negative or negative 0. /// Returns whether x is negative or negative 0.
pub fn signbit(x: var) bool { pub fn signbit(x: var) bool {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f16 => signbit16(x), f16 => signbit16(x),
f32 => signbit32(x), f32 => signbit32(x),

View File

@ -14,8 +14,8 @@ const expect = std.testing.expect;
/// - sin(+-0) = +-0 /// - sin(+-0) = +-0
/// - sin(+-inf) = nan /// - sin(+-inf) = nan
/// - sin(nan) = nan /// - sin(nan) = nan
pub fn sin(x: var) @typeOf(x) { pub fn sin(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => sin_(T, x), f32 => sin_(T, x),
f64 => sin_(T, x), f64 => sin_(T, x),

View File

@ -17,8 +17,8 @@ const maxInt = std.math.maxInt;
/// - sinh(+-0) = +-0 /// - sinh(+-0) = +-0
/// - sinh(+-inf) = +-inf /// - sinh(+-inf) = +-inf
/// - sinh(nan) = nan /// - sinh(nan) = nan
pub fn sinh(x: var) @typeOf(x) { pub fn sinh(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => sinh32(x), f32 => sinh32(x),
f64 => sinh64(x), f64 => sinh64(x),

View File

@ -12,8 +12,8 @@ const maxInt = std.math.maxInt;
/// - sqrt(+-0) = +-0 /// - sqrt(+-0) = +-0
/// - sqrt(x) = nan if x < 0 /// - sqrt(x) = nan if x < 0
/// - sqrt(nan) = nan /// - sqrt(nan) = nan
pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typeOf(x).bit_count / 2) else @typeOf(x)) { pub fn sqrt(x: var) (if (@typeId(@TypeOf(x)) == TypeId.Int) @IntType(false, @TypeOf(x).bit_count / 2) else @TypeOf(x)) {
const T = @typeOf(x); const T = @TypeOf(x);
switch (@typeId(T)) { switch (@typeId(T)) {
TypeId.ComptimeFloat => return @as(T, @sqrt(f64, x)), // TODO upgrade to f128 TypeId.ComptimeFloat => return @as(T, @sqrt(f64, x)), // TODO upgrade to f128
TypeId.Float => return @sqrt(T, x), TypeId.Float => return @sqrt(T, x),

View File

@ -14,8 +14,8 @@ const expect = std.testing.expect;
/// - tan(+-0) = +-0 /// - tan(+-0) = +-0
/// - tan(+-inf) = nan /// - tan(+-inf) = nan
/// - tan(nan) = nan /// - tan(nan) = nan
pub fn tan(x: var) @typeOf(x) { pub fn tan(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => tan_(f32, x), f32 => tan_(f32, x),
f64 => tan_(f64, x), f64 => tan_(f64, x),

View File

@ -17,8 +17,8 @@ const maxInt = std.math.maxInt;
/// - sinh(+-0) = +-0 /// - sinh(+-0) = +-0
/// - sinh(+-inf) = +-1 /// - sinh(+-inf) = +-1
/// - sinh(nan) = nan /// - sinh(nan) = nan
pub fn tanh(x: var) @typeOf(x) { pub fn tanh(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => tanh32(x), f32 => tanh32(x),
f64 => tanh64(x), f64 => tanh64(x),

View File

@ -15,8 +15,8 @@ const maxInt = std.math.maxInt;
/// - trunc(+-0) = +-0 /// - trunc(+-0) = +-0
/// - trunc(+-inf) = +-inf /// - trunc(+-inf) = +-inf
/// - trunc(nan) = nan /// - trunc(nan) = nan
pub fn trunc(x: var) @typeOf(x) { pub fn trunc(x: var) @TypeOf(x) {
const T = @typeOf(x); const T = @TypeOf(x);
return switch (T) { return switch (T) {
f32 => trunc32(x), f32 => trunc32(x),
f64 => trunc64(x), f64 => trunc64(x),

View File

@ -86,7 +86,7 @@ pub const Allocator = struct {
/// `ptr` should be the return value of `create`, or otherwise /// `ptr` should be the return value of `create`, or otherwise
/// have the same address and alignment property. /// have the same address and alignment property.
pub fn destroy(self: *Allocator, ptr: var) void { pub fn destroy(self: *Allocator, ptr: var) void {
const T = @typeOf(ptr).Child; const T = @TypeOf(ptr).Child;
if (@sizeOf(T) == 0) return; if (@sizeOf(T) == 0) return;
const non_const_ptr = @intToPtr([*]u8, @ptrToInt(ptr)); const non_const_ptr = @intToPtr([*]u8, @ptrToInt(ptr));
const shrink_result = self.shrinkFn(self, non_const_ptr[0..@sizeOf(T)], @alignOf(T), 0, 1); const shrink_result = self.shrinkFn(self, non_const_ptr[0..@sizeOf(T)], @alignOf(T), 0, 1);
@ -147,10 +147,10 @@ pub const Allocator = struct {
/// If you need guaranteed success, call `shrink`. /// If you need guaranteed success, call `shrink`.
/// If `new_n` is 0, this is the same as `free` and it always succeeds. /// If `new_n` is 0, this is the same as `free` and it always succeeds.
pub fn realloc(self: *Allocator, old_mem: var, new_n: usize) t: { pub fn realloc(self: *Allocator, old_mem: var, new_n: usize) t: {
const Slice = @typeInfo(@typeOf(old_mem)).Pointer; const Slice = @typeInfo(@TypeOf(old_mem)).Pointer;
break :t Error![]align(Slice.alignment) Slice.child; break :t Error![]align(Slice.alignment) Slice.child;
} { } {
const old_alignment = @typeInfo(@typeOf(old_mem)).Pointer.alignment; const old_alignment = @typeInfo(@TypeOf(old_mem)).Pointer.alignment;
return self.alignedRealloc(old_mem, old_alignment, new_n); return self.alignedRealloc(old_mem, old_alignment, new_n);
} }
@ -162,8 +162,8 @@ pub const Allocator = struct {
old_mem: var, old_mem: var,
comptime new_alignment: u29, comptime new_alignment: u29,
new_n: usize, new_n: usize,
) Error![]align(new_alignment) @typeInfo(@typeOf(old_mem)).Pointer.child { ) Error![]align(new_alignment) @typeInfo(@TypeOf(old_mem)).Pointer.child {
const Slice = @typeInfo(@typeOf(old_mem)).Pointer; const Slice = @typeInfo(@TypeOf(old_mem)).Pointer;
const T = Slice.child; const T = Slice.child;
if (old_mem.len == 0) { if (old_mem.len == 0) {
return self.alignedAlloc(T, new_alignment, new_n); return self.alignedAlloc(T, new_alignment, new_n);
@ -189,10 +189,10 @@ pub const Allocator = struct {
/// Returned slice has same alignment as old_mem. /// Returned slice has same alignment as old_mem.
/// Shrinking to 0 is the same as calling `free`. /// Shrinking to 0 is the same as calling `free`.
pub fn shrink(self: *Allocator, old_mem: var, new_n: usize) t: { pub fn shrink(self: *Allocator, old_mem: var, new_n: usize) t: {
const Slice = @typeInfo(@typeOf(old_mem)).Pointer; const Slice = @typeInfo(@TypeOf(old_mem)).Pointer;
break :t []align(Slice.alignment) Slice.child; break :t []align(Slice.alignment) Slice.child;
} { } {
const old_alignment = @typeInfo(@typeOf(old_mem)).Pointer.alignment; const old_alignment = @typeInfo(@TypeOf(old_mem)).Pointer.alignment;
return self.alignedShrink(old_mem, old_alignment, new_n); return self.alignedShrink(old_mem, old_alignment, new_n);
} }
@ -204,8 +204,8 @@ pub const Allocator = struct {
old_mem: var, old_mem: var,
comptime new_alignment: u29, comptime new_alignment: u29,
new_n: usize, new_n: usize,
) []align(new_alignment) @typeInfo(@typeOf(old_mem)).Pointer.child { ) []align(new_alignment) @typeInfo(@TypeOf(old_mem)).Pointer.child {
const Slice = @typeInfo(@typeOf(old_mem)).Pointer; const Slice = @typeInfo(@TypeOf(old_mem)).Pointer;
const T = Slice.child; const T = Slice.child;
if (new_n == 0) { if (new_n == 0) {
@ -229,7 +229,7 @@ pub const Allocator = struct {
/// Free an array allocated with `alloc`. To free a single item, /// Free an array allocated with `alloc`. To free a single item,
/// see `destroy`. /// see `destroy`.
pub fn free(self: *Allocator, memory: var) void { pub fn free(self: *Allocator, memory: var) void {
const Slice = @typeInfo(@typeOf(memory)).Pointer; const Slice = @typeInfo(@TypeOf(memory)).Pointer;
const bytes = @sliceToBytes(memory); const bytes = @sliceToBytes(memory);
if (bytes.len == 0) return; if (bytes.len == 0) return;
const non_const_ptr = @intToPtr([*]u8, @ptrToInt(bytes.ptr)); const non_const_ptr = @intToPtr([*]u8, @ptrToInt(bytes.ptr));
@ -1323,8 +1323,8 @@ fn AsBytesReturnType(comptime P: type) type {
} }
///Given a pointer to a single item, returns a slice of the underlying bytes, preserving constness. ///Given a pointer to a single item, returns a slice of the underlying bytes, preserving constness.
pub fn asBytes(ptr: var) AsBytesReturnType(@typeOf(ptr)) { pub fn asBytes(ptr: var) AsBytesReturnType(@TypeOf(ptr)) {
const P = @typeOf(ptr); const P = @TypeOf(ptr);
return @ptrCast(AsBytesReturnType(P), ptr); return @ptrCast(AsBytesReturnType(P), ptr);
} }
@ -1363,7 +1363,7 @@ test "asBytes" {
} }
///Given any value, returns a copy of its bytes in an array. ///Given any value, returns a copy of its bytes in an array.
pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 { pub fn toBytes(value: var) [@sizeOf(@TypeOf(value))]u8 {
return asBytes(&value).*; return asBytes(&value).*;
} }
@ -1397,8 +1397,8 @@ fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {
///Given a pointer to an array of bytes, returns a pointer to a value of the specified type ///Given a pointer to an array of bytes, returns a pointer to a value of the specified type
/// backed by those bytes, preserving constness. /// backed by those bytes, preserving constness.
pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @typeOf(bytes)) { pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @TypeOf(bytes)) {
return @ptrCast(BytesAsValueReturnType(T, @typeOf(bytes)), bytes); return @ptrCast(BytesAsValueReturnType(T, @TypeOf(bytes)), bytes);
} }
test "bytesAsValue" { test "bytesAsValue" {
@ -1460,11 +1460,11 @@ fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type {
} }
///Given a pointer to an array, returns a pointer to a portion of that array, preserving constness. ///Given a pointer to an array, returns a pointer to a portion of that array, preserving constness.
pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubArrayPtrReturnType(@typeOf(ptr), length) { pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubArrayPtrReturnType(@TypeOf(ptr), length) {
assert(start + length <= ptr.*.len); assert(start + length <= ptr.*.len);
const ReturnType = SubArrayPtrReturnType(@typeOf(ptr), length); const ReturnType = SubArrayPtrReturnType(@TypeOf(ptr), length);
const T = meta.Child(meta.Child(@typeOf(ptr))); const T = meta.Child(meta.Child(@TypeOf(ptr)));
return @ptrCast(ReturnType, &ptr[start]); return @ptrCast(ReturnType, &ptr[start]);
} }

View File

@ -11,7 +11,7 @@ const TypeId = builtin.TypeId;
const TypeInfo = builtin.TypeInfo; const TypeInfo = builtin.TypeInfo;
pub fn tagName(v: var) []const u8 { pub fn tagName(v: var) []const u8 {
const T = @typeOf(v); const T = @TypeOf(v);
switch (@typeInfo(T)) { switch (@typeInfo(T)) {
TypeId.ErrorSet => return @errorName(v), TypeId.ErrorSet => return @errorName(v),
else => return @tagName(v), else => return @tagName(v),
@ -339,8 +339,8 @@ test "std.meta.TagType" {
} }
///Returns the active tag of a tagged union ///Returns the active tag of a tagged union
pub fn activeTag(u: var) @TagType(@typeOf(u)) { pub fn activeTag(u: var) @TagType(@TypeOf(u)) {
const T = @typeOf(u); const T = @TypeOf(u);
return @as(@TagType(T), u); return @as(@TagType(T), u);
} }
@ -365,7 +365,7 @@ test "std.meta.activeTag" {
///Given a tagged union type, and an enum, return the type of the union ///Given a tagged union type, and an enum, return the type of the union
/// field corresponding to the enum tag. /// field corresponding to the enum tag.
pub fn TagPayloadType(comptime U: type, tag: var) type { pub fn TagPayloadType(comptime U: type, tag: var) type {
const Tag = @typeOf(tag); const Tag = @TypeOf(tag);
testing.expect(trait.is(builtin.TypeId.Union)(U)); testing.expect(trait.is(builtin.TypeId.Union)(U));
testing.expect(trait.is(builtin.TypeId.Enum)(Tag)); testing.expect(trait.is(builtin.TypeId.Enum)(Tag));
@ -386,13 +386,13 @@ test "std.meta.TagPayloadType" {
}; };
const MovedEvent = TagPayloadType(Event, Event.Moved); const MovedEvent = TagPayloadType(Event, Event.Moved);
var e: Event = undefined; var e: Event = undefined;
testing.expect(MovedEvent == @typeOf(e.Moved)); testing.expect(MovedEvent == @TypeOf(e.Moved));
} }
///Compares two of any type for equality. Containers are compared on a field-by-field basis, ///Compares two of any type for equality. Containers are compared on a field-by-field basis,
/// where possible. Pointers are not followed. /// where possible. Pointers are not followed.
pub fn eql(a: var, b: @typeOf(a)) bool { pub fn eql(a: var, b: @TypeOf(a)) bool {
const T = @typeOf(a); const T = @TypeOf(a);
switch (@typeId(T)) { switch (@typeId(T)) {
builtin.TypeId.Struct => { builtin.TypeId.Struct => {

View File

@ -13,7 +13,7 @@ fn traitFnWorkaround(comptime T: type) bool {
return false; return false;
} }
pub const TraitFn = @typeOf(traitFnWorkaround); pub const TraitFn = @TypeOf(traitFnWorkaround);
/// ///
//////Trait generators //////Trait generators
@ -61,7 +61,7 @@ pub fn hasFn(comptime name: []const u8) TraitFn {
pub fn trait(comptime T: type) bool { pub fn trait(comptime T: type) bool {
if (!comptime isContainer(T)) return false; if (!comptime isContainer(T)) return false;
if (!comptime @hasDecl(T, name)) return false; if (!comptime @hasDecl(T, name)) return false;
const DeclType = @typeOf(@field(T, name)); const DeclType = @TypeOf(@field(T, name));
const decl_type_id = @typeId(DeclType); const decl_type_id = @typeId(DeclType);
return decl_type_id == builtin.TypeId.Fn; return decl_type_id == builtin.TypeId.Fn;
} }
@ -236,9 +236,9 @@ pub fn isSingleItemPtr(comptime T: type) bool {
test "std.meta.trait.isSingleItemPtr" { test "std.meta.trait.isSingleItemPtr" {
const array = [_]u8{0} ** 10; const array = [_]u8{0} ** 10;
testing.expect(isSingleItemPtr(@typeOf(&array[0]))); testing.expect(isSingleItemPtr(@TypeOf(&array[0])));
testing.expect(!isSingleItemPtr(@typeOf(array))); testing.expect(!isSingleItemPtr(@TypeOf(array)));
testing.expect(!isSingleItemPtr(@typeOf(array[0..1]))); testing.expect(!isSingleItemPtr(@TypeOf(array[0..1])));
} }
/// ///
@ -253,9 +253,9 @@ pub fn isManyItemPtr(comptime T: type) bool {
test "std.meta.trait.isManyItemPtr" { test "std.meta.trait.isManyItemPtr" {
const array = [_]u8{0} ** 10; const array = [_]u8{0} ** 10;
const mip = @ptrCast([*]const u8, &array[0]); const mip = @ptrCast([*]const u8, &array[0]);
testing.expect(isManyItemPtr(@typeOf(mip))); testing.expect(isManyItemPtr(@TypeOf(mip)));
testing.expect(!isManyItemPtr(@typeOf(array))); testing.expect(!isManyItemPtr(@TypeOf(array)));
testing.expect(!isManyItemPtr(@typeOf(array[0..1]))); testing.expect(!isManyItemPtr(@TypeOf(array[0..1])));
} }
/// ///
@ -269,9 +269,9 @@ pub fn isSlice(comptime T: type) bool {
test "std.meta.trait.isSlice" { test "std.meta.trait.isSlice" {
const array = [_]u8{0} ** 10; const array = [_]u8{0} ** 10;
testing.expect(isSlice(@typeOf(array[0..]))); testing.expect(isSlice(@TypeOf(array[0..])));
testing.expect(!isSlice(@typeOf(array))); testing.expect(!isSlice(@TypeOf(array)));
testing.expect(!isSlice(@typeOf(&array[0]))); testing.expect(!isSlice(@TypeOf(&array[0])));
} }
/// ///
@ -291,10 +291,10 @@ test "std.meta.trait.isIndexable" {
const array = [_]u8{0} ** 10; const array = [_]u8{0} ** 10;
const slice = array[0..]; const slice = array[0..];
testing.expect(isIndexable(@typeOf(array))); testing.expect(isIndexable(@TypeOf(array)));
testing.expect(isIndexable(@typeOf(&array))); testing.expect(isIndexable(@TypeOf(&array)));
testing.expect(isIndexable(@typeOf(slice))); testing.expect(isIndexable(@TypeOf(slice)));
testing.expect(!isIndexable(meta.Child(@typeOf(slice)))); testing.expect(!isIndexable(meta.Child(@TypeOf(slice))));
} }
/// ///
@ -313,8 +313,8 @@ test "std.meta.trait.isNumber" {
testing.expect(isNumber(u32)); testing.expect(isNumber(u32));
testing.expect(isNumber(f32)); testing.expect(isNumber(f32));
testing.expect(isNumber(u64)); testing.expect(isNumber(u64));
testing.expect(isNumber(@typeOf(102))); testing.expect(isNumber(@TypeOf(102)));
testing.expect(isNumber(@typeOf(102.123))); testing.expect(isNumber(@TypeOf(102.123)));
testing.expect(!isNumber([]u8)); testing.expect(!isNumber([]u8));
testing.expect(!isNumber(NotANumber)); testing.expect(!isNumber(NotANumber));
} }
@ -328,10 +328,10 @@ pub fn isConstPtr(comptime T: type) bool {
test "std.meta.trait.isConstPtr" { test "std.meta.trait.isConstPtr" {
var t = @as(u8, 0); var t = @as(u8, 0);
const c = @as(u8, 0); const c = @as(u8, 0);
testing.expect(isConstPtr(*const @typeOf(t))); testing.expect(isConstPtr(*const @TypeOf(t)));
testing.expect(isConstPtr(@typeOf(&c))); testing.expect(isConstPtr(@TypeOf(&c)));
testing.expect(!isConstPtr(*@typeOf(t))); testing.expect(!isConstPtr(*@TypeOf(t)));
testing.expect(!isConstPtr(@typeOf(6))); testing.expect(!isConstPtr(@TypeOf(6)));
} }
pub fn isContainer(comptime T: type) bool { pub fn isContainer(comptime T: type) bool {

View File

@ -11,7 +11,7 @@ const ResetEvent = std.ResetEvent;
/// no-ops. In single threaded debug mode, there is deadlock detection. /// no-ops. In single threaded debug mode, there is deadlock detection.
pub const Mutex = if (builtin.single_threaded) pub const Mutex = if (builtin.single_threaded)
struct { struct {
lock: @typeOf(lock_init), lock: @TypeOf(lock_init),
const lock_init = if (std.debug.runtime_safety) false else {}; const lock_init = if (std.debug.runtime_safety) false else {};

View File

@ -271,7 +271,7 @@ pub const Address = extern union {
options: std.fmt.FormatOptions, options: std.fmt.FormatOptions,
context: var, context: var,
comptime Errors: type, comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void, output: fn (@TypeOf(context), []const u8) Errors!void,
) !void { ) !void {
switch (self.any.family) { switch (self.any.family) {
os.AF_INET => { os.AF_INET => {

View File

@ -2974,7 +2974,7 @@ pub fn res_mkquery(
// Make a reasonably unpredictable id // Make a reasonably unpredictable id
var ts: timespec = undefined; var ts: timespec = undefined;
clock_gettime(CLOCK_REALTIME, &ts) catch {}; clock_gettime(CLOCK_REALTIME, &ts) catch {};
const UInt = @IntType(false, @typeOf(ts.tv_nsec).bit_count); const UInt = @IntType(false, @TypeOf(ts.tv_nsec).bit_count);
const unsec = @bitCast(UInt, ts.tv_nsec); const unsec = @bitCast(UInt, ts.tv_nsec);
const id = @truncate(u32, unsec + unsec / 65536); const id = @truncate(u32, unsec + unsec / 65536);
q[0] = @truncate(u8, id / 256); q[0] = @truncate(u8, id / 256);

View File

@ -706,7 +706,7 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti
.restorer = @ptrCast(extern fn () void, restorer_fn), .restorer = @ptrCast(extern fn () void, restorer_fn),
}; };
var ksa_old: k_sigaction = undefined; var ksa_old: k_sigaction = undefined;
const ksa_mask_size = @sizeOf(@typeOf(ksa_old.mask)); const ksa_mask_size = @sizeOf(@TypeOf(ksa_old.mask));
@memcpy(@ptrCast([*]u8, &ksa.mask), @ptrCast([*]const u8, &act.mask), ksa_mask_size); @memcpy(@ptrCast([*]u8, &ksa.mask), @ptrCast([*]const u8, &act.mask), ksa_mask_size);
const result = syscall4(SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), ksa_mask_size); const result = syscall4(SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), ksa_mask_size);
const err = getErrno(result); const err = getErrno(result);
@ -786,7 +786,7 @@ pub fn sendmsg(fd: i32, msg: *msghdr_const, flags: u32) usize {
} }
pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize { pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize {
if (@typeInfo(usize).Int.bits > @typeInfo(@typeOf(mmsghdr(undefined).msg_len)).Int.bits) { if (@typeInfo(usize).Int.bits > @typeInfo(@TypeOf(mmsghdr(undefined).msg_len)).Int.bits) {
// workaround kernel brokenness: // workaround kernel brokenness:
// if adding up all iov_len overflows a i32 then split into multiple calls // if adding up all iov_len overflows a i32 then split into multiple calls
// see https://www.openwall.com/lists/musl/2014/06/07/5 // see https://www.openwall.com/lists/musl/2014/06/07/5

View File

@ -32,7 +32,7 @@ pub const Guid = extern struct {
options: fmt.FormatOptions, options: fmt.FormatOptions,
context: var, context: var,
comptime Errors: type, comptime Errors: type,
output: fn (@typeOf(context), []const u8) Errors!void, output: fn (@TypeOf(context), []const u8) Errors!void,
) Errors!void { ) Errors!void {
if (f.len == 0) { if (f.len == 0) {
return fmt.format(context, Errors, output, "{x:0>8}-{x:0>4}-{x:0>4}-{x:0>2}{x:0>2}-{x:0>12}", self.time_low, self.time_mid, self.time_high_and_version, self.clock_seq_high_and_reserved, self.clock_seq_low, self.node); return fmt.format(context, Errors, output, "{x:0>8}-{x:0>4}-{x:0>4}-{x:0>2}{x:0>2}-{x:0>12}", self.time_low, self.time_mid, self.time_high_and_version, self.clock_seq_high_and_reserved, self.clock_seq_low, self.node);

View File

@ -214,12 +214,12 @@ pub extern "kernel32" stdcallcc fn WaitForSingleObject(hHandle: HANDLE, dwMillis
pub extern "kernel32" stdcallcc fn WaitForSingleObjectEx(hHandle: HANDLE, dwMilliseconds: DWORD, bAlertable: BOOL) DWORD; pub extern "kernel32" stdcallcc fn WaitForSingleObjectEx(hHandle: HANDLE, dwMilliseconds: DWORD, bAlertable: BOOL) DWORD;
pub extern "kernel32" stdcallcc fn WaitForMultipleObjects(nCount: DWORD, lpHandle: [*]const HANDLE, bWaitAll:BOOL, dwMilliseconds: DWORD) DWORD; pub extern "kernel32" stdcallcc fn WaitForMultipleObjects(nCount: DWORD, lpHandle: [*]const HANDLE, bWaitAll: BOOL, dwMilliseconds: DWORD) DWORD;
pub extern "kernel32" stdcallcc fn WaitForMultipleObjectsEx( pub extern "kernel32" stdcallcc fn WaitForMultipleObjectsEx(
nCount: DWORD, nCount: DWORD,
lpHandle: [*]const HANDLE, lpHandle: [*]const HANDLE,
bWaitAll:BOOL, bWaitAll: BOOL,
dwMilliseconds: DWORD, dwMilliseconds: DWORD,
bAlertable: BOOL, bAlertable: BOOL,
) DWORD; ) DWORD;

View File

@ -635,7 +635,7 @@ const MsfStream = struct {
/// Implementation of InStream trait for Pdb.MsfStream /// Implementation of InStream trait for Pdb.MsfStream
stream: Stream = undefined, stream: Stream = undefined,
pub const Error = @typeOf(read).ReturnType.ErrorSet; pub const Error = @TypeOf(read).ReturnType.ErrorSet;
pub const Stream = io.InStream(Error); pub const Stream = io.InStream(Error);
fn init(block_size: u32, file: File, blocks: []u32) MsfStream { fn init(block_size: u32, file: File, blocks: []u32) MsfStream {

View File

@ -27,7 +27,7 @@ pub const ResetEvent = struct {
pub fn isSet(self: *ResetEvent) bool { pub fn isSet(self: *ResetEvent) bool {
return self.os_event.isSet(); return self.os_event.isSet();
} }
/// Sets the event if not already set and /// Sets the event if not already set and
/// wakes up AT LEAST one thread waiting the event. /// wakes up AT LEAST one thread waiting the event.
/// Returns whether or not a thread was woken up. /// Returns whether or not a thread was woken up.
@ -62,7 +62,7 @@ const OsEvent = if (builtin.single_threaded) DebugEvent else switch (builtin.os)
}; };
const DebugEvent = struct { const DebugEvent = struct {
is_set: @typeOf(set_init), is_set: @TypeOf(set_init),
const set_init = if (std.debug.runtime_safety) false else {}; const set_init = if (std.debug.runtime_safety) false else {};
@ -345,8 +345,8 @@ const PosixEvent = struct {
timeout_abs += @intCast(u64, ts.tv_sec) * time.second; timeout_abs += @intCast(u64, ts.tv_sec) * time.second;
timeout_abs += @intCast(u64, ts.tv_nsec); timeout_abs += @intCast(u64, ts.tv_nsec);
} }
ts.tv_sec = @intCast(@typeOf(ts.tv_sec), @divFloor(timeout_abs, time.second)); ts.tv_sec = @intCast(@TypeOf(ts.tv_sec), @divFloor(timeout_abs, time.second));
ts.tv_nsec = @intCast(@typeOf(ts.tv_nsec), @mod(timeout_abs, time.second)); ts.tv_nsec = @intCast(@TypeOf(ts.tv_nsec), @mod(timeout_abs, time.second));
} }
var dummy_value: u32 = undefined; var dummy_value: u32 = undefined;
@ -426,8 +426,8 @@ test "std.ResetEvent" {
.event = event, .event = event,
.value = 0, .value = 0,
}; };
var receiver = try std.Thread.spawn(&context, Context.receiver); var receiver = try std.Thread.spawn(&context, Context.receiver);
defer receiver.wait(); defer receiver.wait();
try context.sender(); try context.sender();
} }

View File

@ -122,7 +122,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
self.* = undefined; self.* = undefined;
} }
pub fn at(self: var, i: usize) AtType(@typeOf(self)) { pub fn at(self: var, i: usize) AtType(@TypeOf(self)) {
assert(i < self.len); assert(i < self.len);
return self.uncheckedAt(i); return self.uncheckedAt(i);
} }
@ -213,7 +213,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
self.len = new_len; self.len = new_len;
} }
pub fn uncheckedAt(self: var, index: usize) AtType(@typeOf(self)) { pub fn uncheckedAt(self: var, index: usize) AtType(@TypeOf(self)) {
if (index < prealloc_item_count) { if (index < prealloc_item_count) {
return &self.prealloc_segment[index]; return &self.prealloc_segment[index];
} }

View File

@ -125,7 +125,7 @@ pub fn main() !void {
} }
fn runBuild(builder: *Builder) anyerror!void { fn runBuild(builder: *Builder) anyerror!void {
switch (@typeId(@typeOf(root.build).ReturnType)) { switch (@typeId(@TypeOf(root.build).ReturnType)) {
.Void => root.build(builder), .Void => root.build(builder),
.ErrorUnion => try root.build(builder), .ErrorUnion => try root.build(builder),
else => @compileError("expected return type of build to be 'void' or '!void'"), else => @compileError("expected return type of build to be 'void' or '!void'"),

View File

@ -384,7 +384,7 @@ extern fn __aeabi_uidivmod(n: u32, d: u32) extern struct {
} { } {
@setRuntimeSafety(is_test); @setRuntimeSafety(is_test);
var result: @typeOf(__aeabi_uidivmod).ReturnType = undefined; var result: @TypeOf(__aeabi_uidivmod).ReturnType = undefined;
result.q = __udivmodsi4(n, d, &result.r); result.q = __udivmodsi4(n, d, &result.r);
return result; return result;
} }
@ -395,7 +395,7 @@ extern fn __aeabi_uldivmod(n: u64, d: u64) extern struct {
} { } {
@setRuntimeSafety(is_test); @setRuntimeSafety(is_test);
var result: @typeOf(__aeabi_uldivmod).ReturnType = undefined; var result: @TypeOf(__aeabi_uldivmod).ReturnType = undefined;
result.q = __udivmoddi4(n, d, &result.r); result.q = __udivmoddi4(n, d, &result.r);
return result; return result;
} }
@ -406,7 +406,7 @@ extern fn __aeabi_idivmod(n: i32, d: i32) extern struct {
} { } {
@setRuntimeSafety(is_test); @setRuntimeSafety(is_test);
var result: @typeOf(__aeabi_idivmod).ReturnType = undefined; var result: @TypeOf(__aeabi_idivmod).ReturnType = undefined;
result.q = __divmodsi4(n, d, &result.r); result.q = __divmodsi4(n, d, &result.r);
return result; return result;
} }
@ -417,7 +417,7 @@ extern fn __aeabi_ldivmod(n: i64, d: i64) extern struct {
} { } {
@setRuntimeSafety(is_test); @setRuntimeSafety(is_test);
var result: @typeOf(__aeabi_ldivmod).ReturnType = undefined; var result: @TypeOf(__aeabi_ldivmod).ReturnType = undefined;
result.q = __divmoddi4(n, d, &result.r); result.q = __divmoddi4(n, d, &result.r);
return result; return result;
} }

View File

@ -25,7 +25,7 @@ comptime {
} }
} else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) { } else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) {
if (builtin.link_libc and @hasDecl(root, "main")) { if (builtin.link_libc and @hasDecl(root, "main")) {
if (@typeInfo(@typeOf(root.main)).Fn.calling_convention != .C) { if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) {
@export("main", main, .Weak); @export("main", main, .Weak);
} }
} else if (builtin.os == .windows) { } else if (builtin.os == .windows) {
@ -69,7 +69,7 @@ extern fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) u
uefi.handle = handle; uefi.handle = handle;
uefi.system_table = system_table; uefi.system_table = system_table;
switch (@typeInfo(@typeOf(root.main).ReturnType)) { switch (@typeInfo(@TypeOf(root.main).ReturnType)) {
.NoReturn => { .NoReturn => {
root.main(); root.main();
}, },
@ -248,7 +248,7 @@ async fn callMainAsync(loop: *std.event.Loop) u8 {
// This is not marked inline because it is called with @asyncCall when // This is not marked inline because it is called with @asyncCall when
// there is an event loop. // there is an event loop.
fn callMain() u8 { fn callMain() u8 {
switch (@typeInfo(@typeOf(root.main).ReturnType)) { switch (@typeInfo(@TypeOf(root.main).ReturnType)) {
.NoReturn => { .NoReturn => {
root.main(); root.main();
}, },
@ -270,7 +270,7 @@ fn callMain() u8 {
} }
return 1; return 1;
}; };
switch (@typeInfo(@typeOf(result))) { switch (@typeInfo(@TypeOf(result))) {
.Void => return 0, .Void => return 0,
.Int => |info| { .Int => |info| {
if (info.bits != 8) { if (info.bits != 8) {

View File

@ -21,14 +21,14 @@ pub fn expectError(expected_error: anyerror, actual_error_union: var) void {
/// equal, prints diagnostics to stderr to show exactly how they are not equal, /// equal, prints diagnostics to stderr to show exactly how they are not equal,
/// then aborts. /// then aborts.
/// The types must match exactly. /// The types must match exactly.
pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { pub fn expectEqual(expected: var, actual: @TypeOf(expected)) void {
switch (@typeInfo(@typeOf(actual))) { switch (@typeInfo(@TypeOf(actual))) {
.NoReturn, .NoReturn,
.BoundFn, .BoundFn,
.Opaque, .Opaque,
.Frame, .Frame,
.AnyFrame, .AnyFrame,
=> @compileError("value of type " ++ @typeName(@typeOf(actual)) ++ " encountered"), => @compileError("value of type " ++ @typeName(@TypeOf(actual)) ++ " encountered"),
.Undefined, .Undefined,
.Null, .Null,
@ -87,7 +87,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
@compileError("Unable to compare untagged union values"); @compileError("Unable to compare untagged union values");
} }
const TagType = @TagType(@typeOf(expected)); const TagType = @TagType(@TypeOf(expected));
const expectedTag = @as(TagType, expected); const expectedTag = @as(TagType, expected);
const actualTag = @as(TagType, actual); const actualTag = @as(TagType, actual);
@ -95,7 +95,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
expectEqual(expectedTag, actualTag); expectEqual(expectedTag, actualTag);
// we only reach this loop if the tags are equal // we only reach this loop if the tags are equal
inline for (std.meta.fields(@typeOf(actual))) |fld| { inline for (std.meta.fields(@TypeOf(actual))) |fld| {
if (std.mem.eql(u8, fld.name, @tagName(actualTag))) { if (std.mem.eql(u8, fld.name, @tagName(actualTag))) {
expectEqual(@field(expected, fld.name), @field(actual, fld.name)); expectEqual(@field(expected, fld.name), @field(actual, fld.name));
return; return;

View File

@ -147,8 +147,8 @@ pub const Thread = struct {
// https://github.com/ziglang/zig/issues/157 // https://github.com/ziglang/zig/issues/157
const default_stack_size = 16 * 1024 * 1024; const default_stack_size = 16 * 1024 * 1024;
const Context = @typeOf(context); const Context = @TypeOf(context);
comptime assert(@ArgType(@typeOf(startFn), 0) == Context); comptime assert(@ArgType(@TypeOf(startFn), 0) == Context);
if (builtin.os == builtin.Os.windows) { if (builtin.os == builtin.Os.windows) {
const WinThread = struct { const WinThread = struct {
@ -158,7 +158,7 @@ pub const Thread = struct {
}; };
extern fn threadMain(raw_arg: windows.LPVOID) windows.DWORD { extern fn threadMain(raw_arg: windows.LPVOID) windows.DWORD {
const arg = if (@sizeOf(Context) == 0) {} else @ptrCast(*Context, @alignCast(@alignOf(Context), raw_arg)).*; const arg = if (@sizeOf(Context) == 0) {} else @ptrCast(*Context, @alignCast(@alignOf(Context), raw_arg)).*;
switch (@typeId(@typeOf(startFn).ReturnType)) { switch (@typeId(@TypeOf(startFn).ReturnType)) {
.Int => { .Int => {
return startFn(arg); return startFn(arg);
}, },
@ -201,7 +201,7 @@ pub const Thread = struct {
extern fn linuxThreadMain(ctx_addr: usize) u8 { extern fn linuxThreadMain(ctx_addr: usize) u8 {
const arg = if (@sizeOf(Context) == 0) {} else @intToPtr(*const Context, ctx_addr).*; const arg = if (@sizeOf(Context) == 0) {} else @intToPtr(*const Context, ctx_addr).*;
switch (@typeId(@typeOf(startFn).ReturnType)) { switch (@typeId(@TypeOf(startFn).ReturnType)) {
.Int => { .Int => {
return startFn(arg); return startFn(arg);
}, },

View File

@ -13,19 +13,19 @@ pub const Error = error{
}; };
/// Returns whether anything changed /// Returns whether anything changed
pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@typeOf(stream).Child.Error || Error)!bool { pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@TypeOf(stream).Child.Error || Error)!bool {
comptime assert(@typeId(@typeOf(stream)) == builtin.TypeId.Pointer); comptime assert(@typeId(@TypeOf(stream)) == builtin.TypeId.Pointer);
var anything_changed: bool = false; var anything_changed: bool = false;
// make a passthrough stream that checks whether something changed // make a passthrough stream that checks whether something changed
const MyStream = struct { const MyStream = struct {
const MyStream = @This(); const MyStream = @This();
const StreamError = @typeOf(stream).Child.Error; const StreamError = @TypeOf(stream).Child.Error;
const Stream = std.io.OutStream(StreamError); const Stream = std.io.OutStream(StreamError);
anything_changed_ptr: *bool, anything_changed_ptr: *bool,
child_stream: @typeOf(stream), child_stream: @TypeOf(stream),
stream: Stream, stream: Stream,
source_index: usize, source_index: usize,
source: []const u8, source: []const u8,
@ -70,7 +70,7 @@ fn renderRoot(
allocator: *mem.Allocator, allocator: *mem.Allocator,
stream: var, stream: var,
tree: *ast.Tree, tree: *ast.Tree,
) (@typeOf(stream).Child.Error || Error)!void { ) (@TypeOf(stream).Child.Error || Error)!void {
var tok_it = tree.tokens.iterator(0); var tok_it = tree.tokens.iterator(0);
// render all the line comments at the beginning of the file // render all the line comments at the beginning of the file
@ -190,7 +190,7 @@ fn renderRoot(
} }
} }
fn renderExtraNewline(tree: *ast.Tree, stream: var, start_col: *usize, node: *ast.Node) @typeOf(stream).Child.Error!void { fn renderExtraNewline(tree: *ast.Tree, stream: var, start_col: *usize, node: *ast.Node) @TypeOf(stream).Child.Error!void {
const first_token = node.firstToken(); const first_token = node.firstToken();
var prev_token = first_token; var prev_token = first_token;
while (tree.tokens.at(prev_token - 1).id == .DocComment) { while (tree.tokens.at(prev_token - 1).id == .DocComment) {
@ -204,7 +204,7 @@ fn renderExtraNewline(tree: *ast.Tree, stream: var, start_col: *usize, node: *as
} }
} }
fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, indent: usize, start_col: *usize, decl: *ast.Node) (@typeOf(stream).Child.Error || Error)!void { fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, indent: usize, start_col: *usize, decl: *ast.Node) (@TypeOf(stream).Child.Error || Error)!void {
switch (decl.id) { switch (decl.id) {
.FnProto => { .FnProto => {
const fn_proto = @fieldParentPtr(ast.Node.FnProto, "base", decl); const fn_proto = @fieldParentPtr(ast.Node.FnProto, "base", decl);
@ -325,7 +325,7 @@ fn renderExpression(
start_col: *usize, start_col: *usize,
base: *ast.Node, base: *ast.Node,
space: Space, space: Space,
) (@typeOf(stream).Child.Error || Error)!void { ) (@TypeOf(stream).Child.Error || Error)!void {
switch (base.id) { switch (base.id) {
.Identifier => { .Identifier => {
const identifier = @fieldParentPtr(ast.Node.Identifier, "base", base); const identifier = @fieldParentPtr(ast.Node.Identifier, "base", base);
@ -1903,7 +1903,7 @@ fn renderVarDecl(
indent: usize, indent: usize,
start_col: *usize, start_col: *usize,
var_decl: *ast.Node.VarDecl, var_decl: *ast.Node.VarDecl,
) (@typeOf(stream).Child.Error || Error)!void { ) (@TypeOf(stream).Child.Error || Error)!void {
if (var_decl.visib_token) |visib_token| { if (var_decl.visib_token) |visib_token| {
try renderToken(tree, stream, visib_token, indent, start_col, Space.Space); // pub try renderToken(tree, stream, visib_token, indent, start_col, Space.Space); // pub
} }
@ -1976,7 +1976,7 @@ fn renderParamDecl(
start_col: *usize, start_col: *usize,
base: *ast.Node, base: *ast.Node,
space: Space, space: Space,
) (@typeOf(stream).Child.Error || Error)!void { ) (@TypeOf(stream).Child.Error || Error)!void {
const param_decl = @fieldParentPtr(ast.Node.ParamDecl, "base", base); const param_decl = @fieldParentPtr(ast.Node.ParamDecl, "base", base);
try renderDocComments(tree, stream, param_decl, indent, start_col); try renderDocComments(tree, stream, param_decl, indent, start_col);
@ -2005,7 +2005,7 @@ fn renderStatement(
indent: usize, indent: usize,
start_col: *usize, start_col: *usize,
base: *ast.Node, base: *ast.Node,
) (@typeOf(stream).Child.Error || Error)!void { ) (@TypeOf(stream).Child.Error || Error)!void {
switch (base.id) { switch (base.id) {
.VarDecl => { .VarDecl => {
const var_decl = @fieldParentPtr(ast.Node.VarDecl, "base", base); const var_decl = @fieldParentPtr(ast.Node.VarDecl, "base", base);
@ -2044,7 +2044,7 @@ fn renderTokenOffset(
start_col: *usize, start_col: *usize,
space: Space, space: Space,
token_skip_bytes: usize, token_skip_bytes: usize,
) (@typeOf(stream).Child.Error || Error)!void { ) (@TypeOf(stream).Child.Error || Error)!void {
if (space == Space.BlockStart) { if (space == Space.BlockStart) {
if (start_col.* < indent + indent_delta) if (start_col.* < indent + indent_delta)
return renderToken(tree, stream, token_index, indent, start_col, Space.Space); return renderToken(tree, stream, token_index, indent, start_col, Space.Space);
@ -2232,7 +2232,7 @@ fn renderToken(
indent: usize, indent: usize,
start_col: *usize, start_col: *usize,
space: Space, space: Space,
) (@typeOf(stream).Child.Error || Error)!void { ) (@TypeOf(stream).Child.Error || Error)!void {
return renderTokenOffset(tree, stream, token_index, indent, start_col, space, 0); return renderTokenOffset(tree, stream, token_index, indent, start_col, space, 0);
} }
@ -2242,7 +2242,7 @@ fn renderDocComments(
node: var, node: var,
indent: usize, indent: usize,
start_col: *usize, start_col: *usize,
) (@typeOf(stream).Child.Error || Error)!void { ) (@TypeOf(stream).Child.Error || Error)!void {
const comment = node.doc_comments orelse return; const comment = node.doc_comments orelse return;
var it = comment.lines.iterator(0); var it = comment.lines.iterator(0);
const first_token = node.firstToken(); const first_token = node.firstToken();
@ -2308,7 +2308,7 @@ const FindByteOutStream = struct {
} }
}; };
fn copyFixingWhitespace(stream: var, slice: []const u8) @typeOf(stream).Child.Error!void { fn copyFixingWhitespace(stream: var, slice: []const u8) @TypeOf(stream).Child.Error!void {
for (slice) |byte| switch (byte) { for (slice) |byte| switch (byte) {
'\t' => try stream.write(" "), '\t' => try stream.write(" "),
'\r' => {}, '\r' => {},

View File

@ -1021,8 +1021,8 @@ comptime {
// output: must be a function that takes a `self` idiom parameter // output: must be a function that takes a `self` idiom parameter
// and a bytes parameter // and a bytes parameter
// context: must be that self // context: must be that self
fn makeOutput(output: var, context: var) Output(@typeOf(output)) { fn makeOutput(output: var, context: var) Output(@TypeOf(output)) {
return Output(@typeOf(output)){ return Output(@TypeOf(output)){
.output = output, .output = output,
.context = context, .context = context,
}; };

View File

@ -1807,7 +1807,7 @@ pub const Builder = struct {
// Look at the params and ref() other instructions // Look at the params and ref() other instructions
comptime var i = 0; comptime var i = 0;
inline while (i < @memberCount(I.Params)) : (i += 1) { inline while (i < @memberCount(I.Params)) : (i += 1) {
const FieldType = comptime @typeOf(@field(@as(I.Params, undefined), @memberName(I.Params, i))); const FieldType = comptime @TypeOf(@field(@as(I.Params, undefined), @memberName(I.Params, i)));
switch (FieldType) { switch (FieldType) {
*Inst => @field(inst.params, @memberName(I.Params, i)).ref(self), *Inst => @field(inst.params, @memberName(I.Params, i)).ref(self),
*BasicBlock => @field(inst.params, @memberName(I.Params, i)).ref(self), *BasicBlock => @field(inst.params, @memberName(I.Params, i)).ref(self),

View File

@ -72,7 +72,7 @@ pub const LibCInstallation = struct {
inline for (keys) |key, i| { inline for (keys) |key, i| {
if (std.mem.eql(u8, name, key)) { if (std.mem.eql(u8, name, key)) {
found_keys[i].found = true; found_keys[i].found = true;
switch (@typeInfo(@typeOf(@field(self, key)))) { switch (@typeInfo(@TypeOf(@field(self, key)))) {
.Optional => { .Optional => {
if (value.len == 0) { if (value.len == 0) {
@field(self, key) = null; @field(self, key) = null;

View File

@ -1147,7 +1147,7 @@ fn transCreateNodeAPInt(c: *Context, int: ?*const ZigClangAPSInt) !*ast.Node {
var big = try std.math.big.Int.initCapacity(c.a(), num_limbs); var big = try std.math.big.Int.initCapacity(c.a(), num_limbs);
defer big.deinit(); defer big.deinit();
const data = ZigClangAPSInt_getRawData(int.?); const data = ZigClangAPSInt_getRawData(int.?);
var i: @typeOf(num_limbs) = 0; var i: @TypeOf(num_limbs) = 0;
while (i < num_limbs) : (i += 1) big.limbs[i] = data[i]; while (i < num_limbs) : (i += 1) big.limbs[i] = data[i];
const str = big.toString(c.a(), 10) catch |err| switch (err) { const str = big.toString(c.a(), 10) catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory, error.OutOfMemory => return error.OutOfMemory,
@ -1416,7 +1416,7 @@ fn revertAndWarn(
source_loc: ZigClangSourceLocation, source_loc: ZigClangSourceLocation,
comptime format: []const u8, comptime format: []const u8,
args: var, args: var,
) (@typeOf(err) || error{OutOfMemory}) { ) (@TypeOf(err) || error{OutOfMemory}) {
rp.activate(); rp.activate();
try emitWarning(rp.c, source_loc, format, args); try emitWarning(rp.c, source_loc, format, args);
return err; return err;

View File

@ -1038,14 +1038,14 @@ pub const Type = struct {
}; };
fn hashAny(x: var, comptime seed: u64) u32 { fn hashAny(x: var, comptime seed: u64) u32 {
switch (@typeInfo(@typeOf(x))) { switch (@typeInfo(@TypeOf(x))) {
.Int => |info| { .Int => |info| {
comptime var rng = comptime std.rand.DefaultPrng.init(seed); comptime var rng = comptime std.rand.DefaultPrng.init(seed);
const unsigned_x = @bitCast(@IntType(false, info.bits), x); const unsigned_x = @bitCast(@IntType(false, info.bits), x);
if (info.bits <= 32) { if (info.bits <= 32) {
return @as(u32, unsigned_x) *% comptime rng.random.scalar(u32); return @as(u32, unsigned_x) *% comptime rng.random.scalar(u32);
} else { } else {
return @truncate(u32, unsigned_x *% comptime rng.random.scalar(@typeOf(unsigned_x))); return @truncate(u32, unsigned_x *% comptime rng.random.scalar(@TypeOf(unsigned_x)));
} }
}, },
.Pointer => |info| { .Pointer => |info| {
@ -1069,6 +1069,6 @@ fn hashAny(x: var, comptime seed: u64) u32 {
return hashAny(@as(u32, 1), seed); return hashAny(@as(u32, 1), seed);
} }
}, },
else => @compileError("implement hash function for " ++ @typeName(@typeOf(x))), else => @compileError("implement hash function for " ++ @typeName(@TypeOf(x))),
} }
} }

View File

@ -258,12 +258,12 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
cases.add("order-independent declarations", cases.add("order-independent declarations",
\\const io = @import("std").io; \\const io = @import("std").io;
\\const z = io.stdin_fileno; \\const z = io.stdin_fileno;
\\const x : @typeOf(y) = 1234; \\const x : @TypeOf(y) = 1234;
\\const y : u16 = 5678; \\const y : u16 = 5678;
\\pub fn main() void { \\pub fn main() void {
\\ var x_local : i32 = print_ok(x); \\ var x_local : i32 = print_ok(x);
\\} \\}
\\fn print_ok(val: @typeOf(x)) @typeOf(foo) { \\fn print_ok(val: @TypeOf(x)) @TypeOf(foo) {
\\ const stdout = &io.getStdOut().outStream().stream; \\ const stdout = &io.getStdOut().outStream().stream;
\\ stdout.print("OK\n", .{}) catch unreachable; \\ stdout.print("OK\n", .{}) catch unreachable;
\\ return 0; \\ return 0;

View File

@ -154,7 +154,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ }; \\ };
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:11:25: error: expected type 'u32', found '@typeOf(get_uval).ReturnType.ErrorSet!u32'", "tmp.zig:11:25: error: expected type 'u32', found '@TypeOf(get_uval).ReturnType.ErrorSet!u32'",
}); });
cases.add("asigning to struct or union fields that are not optionals with a function that returns an optional", cases.add("asigning to struct or union fields that are not optionals with a function that returns an optional",
@ -854,7 +854,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add("field access of slices", cases.add("field access of slices",
\\export fn entry() void { \\export fn entry() void {
\\ var slice: []i32 = undefined; \\ var slice: []i32 = undefined;
\\ const info = @typeOf(slice).unknown; \\ const info = @TypeOf(slice).unknown;
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:3:32: error: type '[]i32' does not support field access", "tmp.zig:3:32: error: type '[]i32' does not support field access",
@ -894,7 +894,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add("@sizeOf bad type", cases.add("@sizeOf bad type",
\\export fn entry() usize { \\export fn entry() usize {
\\ return @sizeOf(@typeOf(null)); \\ return @sizeOf(@TypeOf(null));
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:2:20: error: no size available for type '(null)'", "tmp.zig:2:20: error: no size available for type '(null)'",
@ -1033,7 +1033,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add("bogus compile var", cases.add("bogus compile var",
\\const x = @import("builtin").bogus; \\const x = @import("builtin").bogus;
\\export fn entry() usize { return @sizeOf(@typeOf(x)); } \\export fn entry() usize { return @sizeOf(@TypeOf(x)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'", "tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'",
}); });
@ -1080,7 +1080,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\var foo: Foo = undefined; \\var foo: Foo = undefined;
\\ \\
\\export fn entry() usize { \\export fn entry() usize {
\\ return @sizeOf(@typeOf(foo.x)); \\ return @sizeOf(@TypeOf(foo.x));
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:1:13: error: struct 'Foo' depends on itself", "tmp.zig:1:13: error: struct 'Foo' depends on itself",
@ -1118,8 +1118,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
}); });
cases.add("top level decl dependency loop", cases.add("top level decl dependency loop",
\\const a : @typeOf(b) = 0; \\const a : @TypeOf(b) = 0;
\\const b : @typeOf(a) = 0; \\const b : @TypeOf(a) = 0;
\\export fn entry() void { \\export fn entry() void {
\\ const c = a + b; \\ const c = a + b;
\\} \\}
@ -1620,7 +1620,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\var x: f64 = 1.0; \\var x: f64 = 1.0;
\\var y: f32 = x; \\var y: f32 = x;
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(y)); } \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:2:14: error: expected type 'f32', found 'f64'", "tmp.zig:2:14: error: expected type 'f32', found 'f64'",
}); });
@ -2494,7 +2494,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ } \\ }
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:5:14: error: duplicate switch value: '@typeOf(foo).ReturnType.ErrorSet.Foo'", "tmp.zig:5:14: error: duplicate switch value: '@TypeOf(foo).ReturnType.ErrorSet.Foo'",
"tmp.zig:3:14: note: other value is here", "tmp.zig:3:14: note: other value is here",
}); });
@ -2626,7 +2626,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ try foo(); \\ try foo();
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:5:5: error: cannot resolve inferred error set '@typeOf(foo).ReturnType.ErrorSet': function 'foo' not fully analyzed yet", "tmp.zig:5:5: error: cannot resolve inferred error set '@TypeOf(foo).ReturnType.ErrorSet': function 'foo' not fully analyzed yet",
}); });
cases.add("implicit cast of error set not a subset", cases.add("implicit cast of error set not a subset",
@ -3555,7 +3555,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ } \\ }
\\} \\}
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(f)); } \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch", "tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch",
}); });
@ -3577,7 +3577,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ } \\ }
\\} \\}
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(f)); } \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:13:15: error: duplicate switch value", "tmp.zig:13:15: error: duplicate switch value",
"tmp.zig:10:15: note: other value is here", "tmp.zig:10:15: note: other value is here",
@ -3601,7 +3601,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ } \\ }
\\} \\}
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(f)); } \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:13:15: error: duplicate switch value", "tmp.zig:13:15: error: duplicate switch value",
"tmp.zig:10:15: note: other value is here", "tmp.zig:10:15: note: other value is here",
@ -3628,7 +3628,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ 0 => {}, \\ 0 => {},
\\ } \\ }
\\} \\}
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); } \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:2:5: error: switch must handle all possibilities", "tmp.zig:2:5: error: switch must handle all possibilities",
}); });
@ -3642,7 +3642,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ 206 ... 255 => 3, \\ 206 ... 255 => 3,
\\ }; \\ };
\\} \\}
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); } \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:6:9: error: duplicate switch value", "tmp.zig:6:9: error: duplicate switch value",
"tmp.zig:5:14: note: previous value is here", "tmp.zig:5:14: note: previous value is here",
@ -3655,7 +3655,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ } \\ }
\\} \\}
\\const y: u8 = 100; \\const y: u8 = 100;
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); } \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:2:5: error: else prong required when switching on type '*u8'", "tmp.zig:2:5: error: else prong required when switching on type '*u8'",
}); });
@ -3673,7 +3673,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\const derp: usize = 1234; \\const derp: usize = 1234;
\\const a = derp ++ "foo"; \\const a = derp ++ "foo";
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(a)); } \\export fn entry() usize { return @sizeOf(@TypeOf(a)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:3:11: error: expected array, found 'usize'", "tmp.zig:3:11: error: expected array, found 'usize'",
}); });
@ -3683,14 +3683,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ return s ++ "foo"; \\ return s ++ "foo";
\\} \\}
\\var s: [10]u8 = undefined; \\var s: [10]u8 = undefined;
\\export fn entry() usize { return @sizeOf(@typeOf(f)); } \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:2:12: error: unable to evaluate constant expression", "tmp.zig:2:12: error: unable to evaluate constant expression",
}); });
cases.add("@cImport with bogus include", cases.add("@cImport with bogus include",
\\const c = @cImport(@cInclude("bogus.h")); \\const c = @cImport(@cInclude("bogus.h"));
\\export fn entry() usize { return @sizeOf(@typeOf(c.bogo)); } \\export fn entry() usize { return @sizeOf(@TypeOf(c.bogo)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:1:11: error: C import failed", "tmp.zig:1:11: error: C import failed",
".h:1:10: note: 'bogus.h' file not found", ".h:1:10: note: 'bogus.h' file not found",
@ -3700,14 +3700,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\const x = 3; \\const x = 3;
\\const y = &x; \\const y = &x;
\\fn foo() *const i32 { return y; } \\fn foo() *const i32 { return y; }
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); } \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'", "tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'",
}); });
cases.add("integer overflow error", cases.add("integer overflow error",
\\const x : u8 = 300; \\const x : u8 = 300;
\\export fn entry() usize { return @sizeOf(@typeOf(x)); } \\export fn entry() usize { return @sizeOf(@TypeOf(x)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'", "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'",
}); });
@ -3736,7 +3736,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ } \\ }
\\}; \\};
\\ \\
\\const member_fn_type = @typeOf(Foo.member_a); \\const member_fn_type = @TypeOf(Foo.member_a);
\\const members = [_]member_fn_type { \\const members = [_]member_fn_type {
\\ Foo.member_a, \\ Foo.member_a,
\\ Foo.member_b, \\ Foo.member_b,
@ -3746,21 +3746,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ const result = members[index](); \\ const result = members[index]();
\\} \\}
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(f)); } \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:20:34: error: expected 1 arguments, found 0", "tmp.zig:20:34: error: expected 1 arguments, found 0",
}); });
cases.add("missing function name", cases.add("missing function name",
\\fn () void {} \\fn () void {}
\\export fn entry() usize { return @sizeOf(@typeOf(f)); } \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:1:1: error: missing function name", "tmp.zig:1:1: error: missing function name",
}); });
cases.add("missing param name", cases.add("missing param name",
\\fn f(i32) void {} \\fn f(i32) void {}
\\export fn entry() usize { return @sizeOf(@typeOf(f)); } \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:1:6: error: missing parameter name", "tmp.zig:1:6: error: missing parameter name",
}); });
@ -3770,7 +3770,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\fn a() i32 {return 0;} \\fn a() i32 {return 0;}
\\fn b() i32 {return 1;} \\fn b() i32 {return 1;}
\\fn c() i32 {return 2;} \\fn c() i32 {return 2;}
\\export fn entry() usize { return @sizeOf(@typeOf(fns)); } \\export fn entry() usize { return @sizeOf(@TypeOf(fns)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'", "tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'",
}); });
@ -3781,7 +3781,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\pub fn b(x: i32) i32 {return x + 1;} \\pub fn b(x: i32) i32 {return x + 1;}
\\export fn c(x: i32) i32 {return x + 2;} \\export fn c(x: i32) i32 {return x + 2;}
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(fns)); } \\export fn entry() usize { return @sizeOf(@TypeOf(fns)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'extern fn(i32) i32'", "tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'extern fn(i32) i32'",
}); });
@ -3789,7 +3789,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add("colliding invalid top level functions", cases.add("colliding invalid top level functions",
\\fn func() bogus {} \\fn func() bogus {}
\\fn func() bogus {} \\fn func() bogus {}
\\export fn entry() usize { return @sizeOf(@typeOf(func)); } \\export fn entry() usize { return @sizeOf(@TypeOf(func)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:2:1: error: redefinition of 'func'", "tmp.zig:2:1: error: redefinition of 'func'",
}); });
@ -3801,7 +3801,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\var global_var: usize = 1; \\var global_var: usize = 1;
\\fn get() usize { return global_var; } \\fn get() usize { return global_var; }
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(Foo)); } \\export fn entry() usize { return @sizeOf(@TypeOf(Foo)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:5:25: error: unable to evaluate constant expression", "tmp.zig:5:25: error: unable to evaluate constant expression",
"tmp.zig:2:12: note: referenced here", "tmp.zig:2:12: note: referenced here",
@ -3813,7 +3813,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\}; \\};
\\const x = Foo {.field = 1} + Foo {.field = 2}; \\const x = Foo {.field = 1} + Foo {.field = 2};
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(x)); } \\export fn entry() usize { return @sizeOf(@TypeOf(x)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'", "tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'",
}); });
@ -3824,10 +3824,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\const int_x = @as(u32, 1) / @as(u32, 0); \\const int_x = @as(u32, 1) / @as(u32, 0);
\\const float_x = @as(f32, 1.0) / @as(f32, 0.0); \\const float_x = @as(f32, 1.0) / @as(f32, 0.0);
\\ \\
\\export fn entry1() usize { return @sizeOf(@typeOf(lit_int_x)); } \\export fn entry1() usize { return @sizeOf(@TypeOf(lit_int_x)); }
\\export fn entry2() usize { return @sizeOf(@typeOf(lit_float_x)); } \\export fn entry2() usize { return @sizeOf(@TypeOf(lit_float_x)); }
\\export fn entry3() usize { return @sizeOf(@typeOf(int_x)); } \\export fn entry3() usize { return @sizeOf(@TypeOf(int_x)); }
\\export fn entry4() usize { return @sizeOf(@typeOf(float_x)); } \\export fn entry4() usize { return @sizeOf(@TypeOf(float_x)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:1:21: error: division by zero", "tmp.zig:1:21: error: division by zero",
"tmp.zig:2:25: error: division by zero", "tmp.zig:2:25: error: division by zero",
@ -3839,7 +3839,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\const foo = "a \\const foo = "a
\\b"; \\b";
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); } \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:1:15: error: newline not allowed in string literal", "tmp.zig:1:15: error: newline not allowed in string literal",
}); });
@ -3848,7 +3848,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\fn foo() void {} \\fn foo() void {}
\\const invalid = foo > foo; \\const invalid = foo > foo;
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(invalid)); } \\export fn entry() usize { return @sizeOf(@TypeOf(invalid)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:2:21: error: operator not allowed for type 'fn() void'", "tmp.zig:2:21: error: operator not allowed for type 'fn() void'",
}); });
@ -3859,7 +3859,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ return foo(a, b); \\ return foo(a, b);
\\} \\}
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(test1)); } \\export fn entry() usize { return @sizeOf(@TypeOf(test1)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:3:16: error: unable to evaluate constant expression", "tmp.zig:3:16: error: unable to evaluate constant expression",
}); });
@ -3867,7 +3867,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add("assign null to non-optional pointer", cases.add("assign null to non-optional pointer",
\\const a: *u8 = null; \\const a: *u8 = null;
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(a)); } \\export fn entry() usize { return @sizeOf(@TypeOf(a)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:1:16: error: expected type '*u8', found '(null)'", "tmp.zig:1:16: error: expected type '*u8', found '(null)'",
}); });
@ -3887,7 +3887,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ return 1 / x; \\ return 1 / x;
\\} \\}
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(y)); } \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:3:14: error: division by zero", "tmp.zig:3:14: error: division by zero",
"tmp.zig:1:14: note: referenced here", "tmp.zig:1:14: note: referenced here",
@ -3896,7 +3896,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add("branch on undefined value", cases.add("branch on undefined value",
\\const x = if (undefined) true else false; \\const x = if (undefined) true else false;
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(x)); } \\export fn entry() usize { return @sizeOf(@TypeOf(x)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:1:15: error: use of undefined value here causes undefined behavior", "tmp.zig:1:15: error: use of undefined value here causes undefined behavior",
}); });
@ -4276,7 +4276,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ return fibbonaci(x - 1) + fibbonaci(x - 2); \\ return fibbonaci(x - 1) + fibbonaci(x - 2);
\\} \\}
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(seventh_fib_number)); } \\export fn entry() usize { return @sizeOf(@TypeOf(seventh_fib_number)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches", "tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches",
"tmp.zig:1:37: note: referenced here", "tmp.zig:1:37: note: referenced here",
@ -4286,7 +4286,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add("@embedFile with bogus file", cases.add("@embedFile with bogus file",
\\const resource = @embedFile("bogus.txt",); \\const resource = @embedFile("bogus.txt",);
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(resource)); } \\export fn entry() usize { return @sizeOf(@TypeOf(resource)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:1:29: error: unable to find '", "tmp.zig:1:29: error: unable to find '",
"bogus.txt'", "bogus.txt'",
@ -4299,7 +4299,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\const a = Foo {.x = get_it()}; \\const a = Foo {.x = get_it()};
\\extern fn get_it() i32; \\extern fn get_it() i32;
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(a)); } \\export fn entry() usize { return @sizeOf(@TypeOf(a)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:4:21: error: unable to evaluate constant expression", "tmp.zig:4:21: error: unable to evaluate constant expression",
}); });
@ -4315,7 +4315,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\} \\}
\\var global_side_effect = false; \\var global_side_effect = false;
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(a)); } \\export fn entry() usize { return @sizeOf(@TypeOf(a)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:6:26: error: unable to evaluate constant expression", "tmp.zig:6:26: error: unable to evaluate constant expression",
"tmp.zig:4:17: note: referenced here", "tmp.zig:4:17: note: referenced here",
@ -4344,8 +4344,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ return a.* == b.*; \\ return a.* == b.*;
\\} \\}
\\ \\
\\export fn entry1() usize { return @sizeOf(@typeOf(bad_eql_1)); } \\export fn entry1() usize { return @sizeOf(@TypeOf(bad_eql_1)); }
\\export fn entry2() usize { return @sizeOf(@typeOf(bad_eql_2)); } \\export fn entry2() usize { return @sizeOf(@TypeOf(bad_eql_2)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:2:14: error: operator not allowed for type '[]u8'", "tmp.zig:2:14: error: operator not allowed for type '[]u8'",
"tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'", "tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'",
@ -4392,7 +4392,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ return -x; \\ return -x;
\\} \\}
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(y)); } \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:3:12: error: negation caused overflow", "tmp.zig:3:12: error: negation caused overflow",
"tmp.zig:1:14: note: referenced here", "tmp.zig:1:14: note: referenced here",
@ -4404,7 +4404,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ return a + b; \\ return a + b;
\\} \\}
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(y)); } \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:3:14: error: operation caused overflow", "tmp.zig:3:14: error: operation caused overflow",
"tmp.zig:1:14: note: referenced here", "tmp.zig:1:14: note: referenced here",
@ -4416,7 +4416,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ return a - b; \\ return a - b;
\\} \\}
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(y)); } \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:3:14: error: operation caused overflow", "tmp.zig:3:14: error: operation caused overflow",
"tmp.zig:1:14: note: referenced here", "tmp.zig:1:14: note: referenced here",
@ -4428,7 +4428,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ return a * b; \\ return a * b;
\\} \\}
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(y)); } \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:3:14: error: operation caused overflow", "tmp.zig:3:14: error: operation caused overflow",
"tmp.zig:1:14: note: referenced here", "tmp.zig:1:14: note: referenced here",
@ -4440,7 +4440,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ return @truncate(i8, x); \\ return @truncate(i8, x);
\\} \\}
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(f)); } \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:3:26: error: expected signed integer type, found 'u32'", "tmp.zig:3:26: error: expected signed integer type, found 'u32'",
}); });
@ -4480,7 +4480,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\fn f() i32 { \\fn f() i32 {
\\ return foo(1, 2); \\ return foo(1, 2);
\\} \\}
\\export fn entry() usize { return @sizeOf(@typeOf(f)); } \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'", "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'",
}); });
@ -4524,7 +4524,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\fn f(m: []const u8) void { \\fn f(m: []const u8) void {
\\ m.copy(u8, self[0..], m); \\ m.copy(u8, self[0..], m);
\\} \\}
\\export fn entry() usize { return @sizeOf(@typeOf(f)); } \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:3:6: error: no member named 'copy' in '[]const u8'", "tmp.zig:3:6: error: no member named 'copy' in '[]const u8'",
}); });
@ -4537,7 +4537,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ \\
\\ foo.method(1, 2); \\ foo.method(1, 2);
\\} \\}
\\export fn entry() usize { return @sizeOf(@typeOf(f)); } \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:6:15: error: expected 2 arguments, found 3", "tmp.zig:6:15: error: expected 2 arguments, found 3",
}); });
@ -4596,7 +4596,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} }; \\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} };
\\} \\}
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); } \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:5:16: error: use of undeclared identifier 'JsonList'", "tmp.zig:5:16: error: use of undeclared identifier 'JsonList'",
}); });
@ -4655,7 +4655,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT; \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT;
\\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1); \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1);
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(block_aligned_stuff)); } \\export fn entry() usize { return @sizeOf(@TypeOf(block_aligned_stuff)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'", "tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'",
}); });
@ -4683,7 +4683,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\const zero: i32 = 0; \\const zero: i32 = 0;
\\const a = zero{1}; \\const a = zero{1};
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(a)); } \\export fn entry() usize { return @sizeOf(@TypeOf(a)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:2:11: error: expected type 'type', found 'i32'", "tmp.zig:2:11: error: expected type 'type', found 'i32'",
}); });
@ -4715,7 +4715,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ return 0; \\ return 0;
\\} \\}
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(testTrickyDefer)); } \\export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:4:11: error: cannot return from defer expression", "tmp.zig:4:11: error: cannot return from defer expression",
}); });
@ -4730,7 +4730,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add("global variable alignment non power of 2", cases.add("global variable alignment non power of 2",
\\const some_data: [100]u8 align(3) = undefined; \\const some_data: [100]u8 align(3) = undefined;
\\export fn entry() usize { return @sizeOf(@typeOf(some_data)); } \\export fn entry() usize { return @sizeOf(@TypeOf(some_data)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:1:32: error: alignment value 3 is not a power of 2", "tmp.zig:1:32: error: alignment value 3 is not a power of 2",
}); });
@ -4772,7 +4772,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ return x.*; \\ return x.*;
\\} \\}
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); } \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'", "tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'",
}); });
@ -4875,7 +4875,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ return out.*[0..1]; \\ return out.*[0..1];
\\} \\}
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(pass)); } \\export fn entry() usize { return @sizeOf(@TypeOf(pass)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'", "tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'",
}); });
@ -4890,7 +4890,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ return true; \\ return true;
\\} \\}
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); } \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'", "tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'",
}); });
@ -5726,7 +5726,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add("@ArgType arg index out of bounds", cases.add("@ArgType arg index out of bounds",
\\comptime { \\comptime {
\\ _ = @ArgType(@typeOf(add), 2); \\ _ = @ArgType(@TypeOf(add), 2);
\\} \\}
\\fn add(a: i32, b: i32) i32 { return a + b; } \\fn add(a: i32, b: i32) i32 { return a + b; }
, &[_][]const u8{ , &[_][]const u8{
@ -6220,7 +6220,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add("getting return type of generic function", cases.add("getting return type of generic function",
\\fn generic(a: var) void {} \\fn generic(a: var) void {}
\\comptime { \\comptime {
\\ _ = @typeOf(generic).ReturnType; \\ _ = @TypeOf(generic).ReturnType;
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:3:25: error: ReturnType has not been resolved because 'fn(var)var' is generic", "tmp.zig:3:25: error: ReturnType has not been resolved because 'fn(var)var' is generic",
@ -6229,7 +6229,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add("getting @ArgType of generic function", cases.add("getting @ArgType of generic function",
\\fn generic(a: var) void {} \\fn generic(a: var) void {}
\\comptime { \\comptime {
\\ _ = @ArgType(@typeOf(generic), 0); \\ _ = @ArgType(@TypeOf(generic), 0);
\\} \\}
, &[_][]const u8{ , &[_][]const u8{
"tmp.zig:3:36: error: @ArgType could not resolve the type of arg 0 because 'fn(var)var' is generic", "tmp.zig:3:36: error: @ArgType could not resolve the type of arg 0 because 'fn(var)var' is generic",

View File

@ -5,10 +5,10 @@ const builtin = @import("builtin");
var foo: u8 align(4) = 100; var foo: u8 align(4) = 100;
test "global variable alignment" { test "global variable alignment" {
expect(@typeOf(&foo).alignment == 4); expect(@TypeOf(&foo).alignment == 4);
expect(@typeOf(&foo) == *align(4) u8); expect(@TypeOf(&foo) == *align(4) u8);
const slice = @as(*[1]u8, &foo)[0..]; const slice = @as(*[1]u8, &foo)[0..];
expect(@typeOf(slice) == []align(4) u8); expect(@TypeOf(slice) == []align(4) u8);
} }
fn derp() align(@sizeOf(usize) * 2) i32 { fn derp() align(@sizeOf(usize) * 2) i32 {
@ -19,8 +19,8 @@ fn noop4() align(4) void {}
test "function alignment" { test "function alignment" {
expect(derp() == 1234); expect(derp() == 1234);
expect(@typeOf(noop1) == fn () align(1) void); expect(@TypeOf(noop1) == fn () align(1) void);
expect(@typeOf(noop4) == fn () align(4) void); expect(@TypeOf(noop4) == fn () align(4) void);
noop1(); noop1();
noop4(); noop4();
} }
@ -31,7 +31,7 @@ var baz: packed struct {
} = undefined; } = undefined;
test "packed struct alignment" { test "packed struct alignment" {
expect(@typeOf(&baz.b) == *align(1) u32); expect(@TypeOf(&baz.b) == *align(1) u32);
} }
const blah: packed struct { const blah: packed struct {
@ -41,7 +41,7 @@ const blah: packed struct {
} = undefined; } = undefined;
test "bit field alignment" { test "bit field alignment" {
expect(@typeOf(&blah.b) == *align(1:3:1) const u3); expect(@TypeOf(&blah.b) == *align(1:3:1) const u3);
} }
test "default alignment allows unspecified in type syntax" { test "default alignment allows unspecified in type syntax" {
@ -165,28 +165,28 @@ fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {
test "@ptrCast preserves alignment of bigger source" { test "@ptrCast preserves alignment of bigger source" {
var x: u32 align(16) = 1234; var x: u32 align(16) = 1234;
const ptr = @ptrCast(*u8, &x); const ptr = @ptrCast(*u8, &x);
expect(@typeOf(ptr) == *align(16) u8); expect(@TypeOf(ptr) == *align(16) u8);
} }
test "runtime known array index has best alignment possible" { test "runtime known array index has best alignment possible" {
// take full advantage of over-alignment // take full advantage of over-alignment
var array align(4) = [_]u8{ 1, 2, 3, 4 }; var array align(4) = [_]u8{ 1, 2, 3, 4 };
expect(@typeOf(&array[0]) == *align(4) u8); expect(@TypeOf(&array[0]) == *align(4) u8);
expect(@typeOf(&array[1]) == *u8); expect(@TypeOf(&array[1]) == *u8);
expect(@typeOf(&array[2]) == *align(2) u8); expect(@TypeOf(&array[2]) == *align(2) u8);
expect(@typeOf(&array[3]) == *u8); expect(@TypeOf(&array[3]) == *u8);
// because align is too small but we still figure out to use 2 // because align is too small but we still figure out to use 2
var bigger align(2) = [_]u64{ 1, 2, 3, 4 }; var bigger align(2) = [_]u64{ 1, 2, 3, 4 };
expect(@typeOf(&bigger[0]) == *align(2) u64); expect(@TypeOf(&bigger[0]) == *align(2) u64);
expect(@typeOf(&bigger[1]) == *align(2) u64); expect(@TypeOf(&bigger[1]) == *align(2) u64);
expect(@typeOf(&bigger[2]) == *align(2) u64); expect(@TypeOf(&bigger[2]) == *align(2) u64);
expect(@typeOf(&bigger[3]) == *align(2) u64); expect(@TypeOf(&bigger[3]) == *align(2) u64);
// because pointer is align 2 and u32 align % 2 == 0 we can assume align 2 // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2
var smaller align(2) = [_]u32{ 1, 2, 3, 4 }; var smaller align(2) = [_]u32{ 1, 2, 3, 4 };
comptime expect(@typeOf(smaller[0..]) == []align(2) u32); comptime expect(@TypeOf(smaller[0..]) == []align(2) u32);
comptime expect(@typeOf(smaller[0..].ptr) == [*]align(2) u32); comptime expect(@TypeOf(smaller[0..].ptr) == [*]align(2) u32);
testIndex(smaller[0..].ptr, 0, *align(2) u32); testIndex(smaller[0..].ptr, 0, *align(2) u32);
testIndex(smaller[0..].ptr, 1, *align(2) u32); testIndex(smaller[0..].ptr, 1, *align(2) u32);
testIndex(smaller[0..].ptr, 2, *align(2) u32); testIndex(smaller[0..].ptr, 2, *align(2) u32);
@ -199,10 +199,10 @@ test "runtime known array index has best alignment possible" {
testIndex2(array[0..].ptr, 3, *u8); testIndex2(array[0..].ptr, 3, *u8);
} }
fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) void { fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) void {
comptime expect(@typeOf(&smaller[index]) == T); comptime expect(@TypeOf(&smaller[index]) == T);
} }
fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) void { fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) void {
comptime expect(@typeOf(&ptr[index]) == T); comptime expect(@TypeOf(&ptr[index]) == T);
} }
test "alignstack" { test "alignstack" {
@ -303,7 +303,7 @@ test "struct field explicit alignment" {
var node: S.Node = undefined; var node: S.Node = undefined;
node.massive_byte = 100; node.massive_byte = 100;
expect(node.massive_byte == 100); expect(node.massive_byte == 100);
comptime expect(@typeOf(&node.massive_byte) == *align(64) u8); comptime expect(@TypeOf(&node.massive_byte) == *align(64) u8);
expect(@ptrToInt(&node.massive_byte) % 64 == 0); expect(@ptrToInt(&node.massive_byte) % 64 == 0);
} }

View File

@ -30,7 +30,7 @@ test "void arrays" {
var array: [4]void = undefined; var array: [4]void = undefined;
array[0] = void{}; array[0] = void{};
array[1] = array[2]; array[1] = array[2];
expect(@sizeOf(@typeOf(array)) == 0); expect(@sizeOf(@TypeOf(array)) == 0);
expect(array.len == 4); expect(array.len == 4);
} }
@ -109,12 +109,12 @@ test "array literal with specified size" {
test "array child property" { test "array child property" {
var x: [5]i32 = undefined; var x: [5]i32 = undefined;
expect(@typeOf(x).Child == i32); expect(@TypeOf(x).Child == i32);
} }
test "array len property" { test "array len property" {
var x: [5]i32 = undefined; var x: [5]i32 = undefined;
expect(@typeOf(x).len == 5); expect(@TypeOf(x).len == 5);
} }
test "array len field" { test "array len field" {

View File

@ -185,7 +185,7 @@ var a_promise: anyframe = undefined;
var global_result = false; var global_result = false;
async fn testSuspendBlock() void { async fn testSuspendBlock() void {
suspend { suspend {
comptime expect(@typeOf(@frame()) == *@Frame(testSuspendBlock)); comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock));
a_promise = @frame(); a_promise = @frame();
} }
@ -282,7 +282,7 @@ test "async fn pointer in a struct field" {
var foo = Foo{ .bar = simpleAsyncFn2 }; var foo = Foo{ .bar = simpleAsyncFn2 };
var bytes: [64]u8 align(16) = undefined; var bytes: [64]u8 align(16) = undefined;
const f = @asyncCall(&bytes, {}, foo.bar, &data); const f = @asyncCall(&bytes, {}, foo.bar, &data);
comptime expect(@typeOf(f) == anyframe->void); comptime expect(@TypeOf(f) == anyframe->void);
expect(data == 2); expect(data == 2);
resume f; resume f;
expect(data == 4); expect(data == 4);
@ -332,7 +332,7 @@ test "async fn with inferred error set" {
fn doTheTest() void { fn doTheTest() void {
var frame: [1]@Frame(middle) = undefined; var frame: [1]@Frame(middle) = undefined;
var fn_ptr = middle; var fn_ptr = middle;
var result: @typeOf(fn_ptr).ReturnType.ErrorSet!void = undefined; var result: @TypeOf(fn_ptr).ReturnType.ErrorSet!void = undefined;
_ = @asyncCall(@sliceToBytes(frame[0..]), &result, fn_ptr); _ = @asyncCall(@sliceToBytes(frame[0..]), &result, fn_ptr);
resume global_frame; resume global_frame;
std.testing.expectError(error.Fail, result); std.testing.expectError(error.Fail, result);
@ -952,7 +952,7 @@ test "@asyncCall with comptime-known function, but not awaited directly" {
fn doTheTest() void { fn doTheTest() void {
var frame: [1]@Frame(middle) = undefined; var frame: [1]@Frame(middle) = undefined;
var result: @typeOf(middle).ReturnType.ErrorSet!void = undefined; var result: @TypeOf(middle).ReturnType.ErrorSet!void = undefined;
_ = @asyncCall(@sliceToBytes(frame[0..]), &result, middle); _ = @asyncCall(@sliceToBytes(frame[0..]), &result, middle);
resume global_frame; resume global_frame;
std.testing.expectError(error.Fail, result); std.testing.expectError(error.Fail, result);
@ -1009,7 +1009,7 @@ test "@asyncCall using the result location inside the frame" {
var foo = Foo{ .bar = S.simple2 }; var foo = Foo{ .bar = S.simple2 };
var bytes: [64]u8 align(16) = undefined; var bytes: [64]u8 align(16) = undefined;
const f = @asyncCall(&bytes, {}, foo.bar, &data); const f = @asyncCall(&bytes, {}, foo.bar, &data);
comptime expect(@typeOf(f) == anyframe->i32); comptime expect(@TypeOf(f) == anyframe->i32);
expect(data == 2); expect(data == 2);
resume f; resume f;
expect(data == 4); expect(data == 4);
@ -1017,18 +1017,18 @@ test "@asyncCall using the result location inside the frame" {
expect(data == 1234); expect(data == 1234);
} }
test "@typeOf an async function call of generic fn with error union type" { test "@TypeOf an async function call of generic fn with error union type" {
const S = struct { const S = struct {
fn func(comptime x: var) anyerror!i32 { fn func(comptime x: var) anyerror!i32 {
const T = @typeOf(async func(x)); const T = @TypeOf(async func(x));
comptime expect(T == @typeOf(@frame()).Child); comptime expect(T == @TypeOf(@frame()).Child);
return undefined; return undefined;
} }
}; };
_ = async S.func(i32); _ = async S.func(i32);
} }
test "using @typeOf on a generic function call" { test "using @TypeOf on a generic function call" {
const S = struct { const S = struct {
var global_frame: anyframe = undefined; var global_frame: anyframe = undefined;
var global_ok = false; var global_ok = false;
@ -1043,7 +1043,7 @@ test "using @typeOf on a generic function call" {
suspend { suspend {
global_frame = @frame(); global_frame = @frame();
} }
const F = @typeOf(async amain(x - 1)); const F = @TypeOf(async amain(x - 1));
const frame = @intToPtr(*F, @ptrToInt(&buf)); const frame = @intToPtr(*F, @ptrToInt(&buf));
return await @asyncCall(frame, {}, amain, x - 1); return await @asyncCall(frame, {}, amain, x - 1);
} }
@ -1068,7 +1068,7 @@ test "recursive call of await @asyncCall with struct return type" {
suspend { suspend {
global_frame = @frame(); global_frame = @frame();
} }
const F = @typeOf(async amain(x - 1)); const F = @TypeOf(async amain(x - 1));
const frame = @intToPtr(*F, @ptrToInt(&buf)); const frame = @intToPtr(*F, @ptrToInt(&buf));
return await @asyncCall(frame, {}, amain, x - 1); return await @asyncCall(frame, {}, amain, x - 1);
} }
@ -1080,7 +1080,7 @@ test "recursive call of await @asyncCall with struct return type" {
}; };
}; };
var res: S.Foo = undefined; var res: S.Foo = undefined;
var frame: @typeOf(async S.amain(@as(u32, 1))) = undefined; var frame: @TypeOf(async S.amain(@as(u32, 1))) = undefined;
_ = @asyncCall(&frame, &res, S.amain, @as(u32, 1)); _ = @asyncCall(&frame, &res, S.amain, @as(u32, 1));
resume S.global_frame; resume S.global_frame;
expect(S.global_ok); expect(S.global_ok);

Some files were not shown because too many files have changed in this diff Show More