diff --git a/doc/langref.html.in b/doc/langref.html.in index e51e59d562..fe015de733 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -307,7 +307,7 @@ pub fn main() void { assert(optional_value == null); warn("\noptional 1\ntype: {}\nvalue: {}\n", .{ - @typeName(@typeOf(optional_value)), + @typeName(@TypeOf(optional_value)), optional_value, }); @@ -315,7 +315,7 @@ pub fn main() void { assert(optional_value != null); warn("\noptional 2\ntype: {}\nvalue: {}\n", .{ - @typeName(@typeOf(optional_value)), + @typeName(@TypeOf(optional_value)), optional_value, }); @@ -323,14 +323,14 @@ pub fn main() void { var number_or_error: anyerror!i32 = error.ArgNotFound; warn("\nerror union 1\ntype: {}\nvalue: {}\n", .{ - @typeName(@typeOf(number_or_error)), + @typeName(@TypeOf(number_or_error)), number_or_error, }); number_or_error = 1234; warn("\nerror union 2\ntype: {}\nvalue: {}\n", .{ - @typeName(@typeOf(number_or_error)), + @typeName(@TypeOf(number_or_error)), number_or_error, }); } @@ -572,7 +572,7 @@ const mem = @import("std").mem; test "string literals" { const bytes = "hello"; - assert(@typeOf(bytes) == *const [5:0]u8); + assert(@TypeOf(bytes) == *const [5:0]u8); assert(bytes.len == 5); assert(bytes[1] == 'e'); assert(bytes[5] == 0); @@ -1802,7 +1802,7 @@ const assert = std.debug.assert; test "null terminated array" { const array = [_:0]u8 {1, 2, 3, 4}; - assert(@typeOf(array) == [4:0]u8); + assert(@TypeOf(array) == [4:0]u8); assert(array.len == 4); assert(array[4] == 0); } @@ -1885,12 +1885,12 @@ test "address of syntax" { assert(x_ptr.* == 1234); // When you get the address of a const variable, you get a const pointer to a single item. - assert(@typeOf(x_ptr) == *const i32); + assert(@TypeOf(x_ptr) == *const i32); // If you want to mutate the value, you'd need an address of a mutable variable: var y: i32 = 5678; const y_ptr = &y; - assert(@typeOf(y_ptr) == *i32); + assert(@TypeOf(y_ptr) == *i32); y_ptr.* += 1; assert(y_ptr.* == 5679); } @@ -1901,7 +1901,7 @@ test "pointer array access" { // does not support pointer arithmetic. var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; const ptr = &array[2]; - assert(@typeOf(ptr) == *u8); + assert(@TypeOf(ptr) == *u8); assert(array[2] == 3); ptr.* += 1; @@ -1953,7 +1953,7 @@ const assert = @import("std").debug.assert; test "@ptrToInt and @intToPtr" { const ptr = @intToPtr(*i32, 0xdeadbeef); const addr = @ptrToInt(ptr); - assert(@typeOf(addr) == usize); + assert(@TypeOf(addr) == usize); assert(addr == 0xdeadbeef); } {#code_end#} @@ -1968,7 +1968,7 @@ test "comptime @intToPtr" { // ptr is never dereferenced. const ptr = @intToPtr(*i32, 0xdeadbeef); const addr = @ptrToInt(ptr); - assert(@typeOf(addr) == usize); + assert(@TypeOf(addr) == usize); assert(addr == 0xdeadbeef); } } @@ -1984,7 +1984,7 @@ const assert = @import("std").debug.assert; test "volatile" { const mmio_ptr = @intToPtr(*volatile u8, 0x12345678); - assert(@typeOf(mmio_ptr) == *volatile u8); + assert(@TypeOf(mmio_ptr) == *volatile u8); } {#code_end#}
@@ -2041,8 +2041,8 @@ const builtin = @import("builtin"); test "variable alignment" { var x: i32 = 1234; - const align_of_i32 = @alignOf(@typeOf(x)); - assert(@typeOf(&x) == *i32); + const align_of_i32 = @alignOf(@TypeOf(x)); + assert(@TypeOf(&x) == *i32); assert(*i32 == *align(align_of_i32) i32); if (builtin.arch == builtin.Arch.x86_64) { assert((*i32).alignment == 4); @@ -2063,10 +2063,10 @@ const assert = @import("std").debug.assert; var foo: u8 align(4) = 100; test "global variable alignment" { - assert(@typeOf(&foo).alignment == 4); - assert(@typeOf(&foo) == *align(4) u8); + assert(@TypeOf(&foo).alignment == 4); + assert(@TypeOf(&foo) == *align(4) u8); const slice = @as(*[1]u8, &foo)[0..]; - assert(@typeOf(slice) == []align(4) u8); + assert(@TypeOf(slice) == []align(4) u8); } fn derp() align(@sizeOf(usize) * 2) i32 { return 1234; } @@ -2075,8 +2075,8 @@ fn noop4() align(4) void {} test "function alignment" { assert(derp() == 1234); - assert(@typeOf(noop1) == fn() align(1) void); - assert(@typeOf(noop4) == fn() align(4) void); + assert(@TypeOf(noop1) == fn() align(1) void); + assert(@TypeOf(noop4) == fn() align(4) void); noop1(); noop4(); } @@ -2162,8 +2162,8 @@ test "basic slices" { // Using the address-of operator on a slice gives a pointer to a single // item, while using the `ptr` field gives an unknown length pointer. - assert(@typeOf(slice.ptr) == [*]i32); - assert(@typeOf(&slice[0]) == *i32); + assert(@TypeOf(slice.ptr) == [*]i32); + assert(@TypeOf(&slice[0]) == *i32); assert(@ptrToInt(slice.ptr) == @ptrToInt(&slice[0])); // Slices have array bounds checking. If you try to access something out @@ -2208,7 +2208,7 @@ test "slice pointer" { slice[2] = 3; assert(slice[2] == 3); // The slice is mutable because we sliced a mutable pointer. - assert(@typeOf(slice) == []u8); + assert(@TypeOf(slice) == []u8); // You can also slice a slice: const slice2 = slice[2..3]; @@ -3566,7 +3566,7 @@ test "for basics" { // This is zero-indexed. var sum2: i32 = 0; for (items) |value, i| { - assert(@typeOf(i) == usize); + assert(@TypeOf(i) == usize); sum2 += @intCast(i32, i); } assert(sum2 == 10); @@ -3909,7 +3909,7 @@ test "type of unreachable" { // However this assertion will still fail because // evaluating unreachable at compile-time is a compile error. - assert(@typeOf(unreachable) == noreturn); + assert(@TypeOf(unreachable) == noreturn); } } {#code_end#} @@ -4018,7 +4018,7 @@ test "function" { const assert = @import("std").debug.assert; comptime { - assert(@typeOf(foo) == fn()void); + assert(@TypeOf(foo) == fn()void); assert(@sizeOf(fn()void) == @sizeOf(?fn()void)); } @@ -4062,35 +4062,35 @@ test "pass struct to function" {
{#header_close#} {#header_open|Function Parameter Type Inference#} -- Function parameters can be declared with {#syntax#}var{#endsyntax#} in place of the type. +
+ Function parameters can be declared with {#syntax#}var{#endsyntax#} in place of the type. In this case the parameter types will be inferred when the function is called. - Use {#link|@typeOf#} and {#link|@typeInfo#} to get information about the inferred type. + Use {#link|@TypeOf#} and {#link|@typeInfo#} to get information about the inferred type.
{#code_begin|test#} const assert = @import("std").debug.assert; -fn addFortyTwo(x: var) @typeOf(x) { +fn addFortyTwo(x: var) @TypeOf(x) { return x + 42; } test "fn type inference" { assert(addFortyTwo(1) == 43); - assert(@typeOf(addFortyTwo(1)) == comptime_int); + assert(@TypeOf(addFortyTwo(1)) == comptime_int); var y: i64 = 2; assert(addFortyTwo(y) == 44); - assert(@typeOf(addFortyTwo(y)) == i64); + assert(@TypeOf(addFortyTwo(y)) == i64); } {#code_end#} - + {#header_close#} {#header_open|Function Reflection#} {#code_begin|test#} const assert = @import("std").debug.assert; test "fn reflection" { - assert(@typeOf(assert).ReturnType == void); - assert(@typeOf(assert).is_var_args == false); + assert(@TypeOf(assert).ReturnType == void); + assert(@TypeOf(assert).is_var_args == false); } {#code_end#} {#header_close#} @@ -4390,10 +4390,10 @@ test "error union" { foo = error.SomeError; // Use compile-time reflection to access the payload type of an error union: - comptime assert(@typeOf(foo).Payload == i32); + comptime assert(@TypeOf(foo).Payload == i32); // Use compile-time reflection to access the error set type of an error union: - comptime assert(@typeOf(foo).ErrorSet == anyerror); + comptime assert(@TypeOf(foo).ErrorSet == anyerror); } {#code_end#} {#header_open|Merging Error Sets#} @@ -4770,7 +4770,7 @@ test "optional type" { foo = 1234; // Use compile-time reflection to access the child type of the optional: - comptime assert(@typeOf(foo).Child == i32); + comptime assert(@TypeOf(foo).Child == i32); } {#code_end#} {#header_close#} @@ -5154,7 +5154,7 @@ test "peer resolve int widening" { var b: i16 = 34; var c = a + b; assert(c == 46); - assert(@typeOf(c) == i16); + assert(@TypeOf(c) == i16); } test "peer resolve arrays of different size to const slice" { @@ -5949,7 +5949,7 @@ pub fn printf(self: *OutStream, arg0: i32, arg1: []const u8) !void { {#code_begin|syntax#} pub fn printValue(self: *OutStream, value: var) !void { - const T = @typeOf(value); + const T = @TypeOf(value); if (@isInteger(T)) { return self.printInt(T, value); } else if (@isFloat(T)) { @@ -6265,7 +6265,7 @@ test "async function suspend with block" { fn testSuspendBlock() void { suspend { - comptime assert(@typeOf(@frame()) == *@Frame(testSuspendBlock)); + comptime assert(@TypeOf(@frame()) == *@Frame(testSuspendBlock)); the_frame = @frame(); } result = true; @@ -6332,7 +6332,7 @@ test "async and await" { fn amain() void { var frame = async func(); - comptime assert(@typeOf(frame) == @Frame(func)); + comptime assert(@TypeOf(frame) == @Frame(func)); const ptr: anyframe->void = &frame; const any_ptr: anyframe = ptr; @@ -6740,7 +6740,7 @@ async fn func(y: *i32) void { Converts a value of one type to another type.- Asserts that {#syntax#}@sizeOf(@typeOf(value)) == @sizeOf(DestType){#endsyntax#}. + Asserts that {#syntax#}@sizeOf(@TypeOf(value)) == @sizeOf(DestType){#endsyntax#}.
Asserts that {#syntax#}@typeId(DestType) != @import("builtin").TypeId.Pointer{#endsyntax#}. Use {#syntax#}@ptrCast{#endsyntax#} or {#syntax#}@intToPtr{#endsyntax#} if you need this. @@ -7045,7 +7045,7 @@ fn cmpxchgStrongButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_v
{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("builtin").AtomicOrder{#endsyntax#}.
-{#syntax#}@typeOf(ptr).alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}
+{#syntax#}@TypeOf(ptr).alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}
{#see_also|Compile Variables|cmpxchgWeak#} {#header_close#} {#header_open|@cmpxchgWeak#} @@ -7073,7 +7073,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("builtin").AtomicOrder{#endsyntax#}.
-{#syntax#}@typeOf(ptr).alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}
+{#syntax#}@TypeOf(ptr).alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}
{#see_also|Compile Variables|cmpxchgStrong#} {#header_close#} @@ -8020,7 +8020,7 @@ test "@setRuntimeSafety" { {#header_close#} {#header_open|@splat#} -{#syntax#}@splat(comptime len: u32, scalar: var) @Vector(len, @typeOf(scalar)){#endsyntax#}
+ {#syntax#}@splat(comptime len: u32, scalar: var) @Vector(len, @TypeOf(scalar)){#endsyntax#}
Produces a vector of length {#syntax#}len{#endsyntax#} where each element is the value {#syntax#}scalar{#endsyntax#}: @@ -8032,7 +8032,7 @@ const assert = std.debug.assert; test "vector @splat" { const scalar: u32 = 5; const result = @splat(4, scalar); - comptime assert(@typeOf(result) == @Vector(4, u32)); + comptime assert(@TypeOf(result) == @Vector(4, u32)); assert(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 })); } {#code_end#} @@ -8250,8 +8250,8 @@ test "integer truncation" {
For these types it is a @@ -8516,20 +8516,20 @@ pub const TypeInfo = union(TypeId) { {#header_close#} - {#header_open|@typeOf#} -
{#syntax#}@typeOf(expression) type{#endsyntax#}
+ {#header_open|@TypeOf#}
+ {#syntax#}@TypeOf(expression) type{#endsyntax#}
This function returns a compile-time constant, which is the type of the expression passed as an argument. The expression is evaluated.
-{#syntax#}@typeOf{#endsyntax#} guarantees no run-time side-effects within the expression:
+{#syntax#}@TypeOf{#endsyntax#} guarantees no run-time side-effects within the expression:
{#code_begin|test#} const std = @import("std"); const assert = std.debug.assert; test "no runtime side effects" { var data: i32 = 0; - const T = @typeOf(foo(i32, &data)); + const T = @TypeOf(foo(i32, &data)); comptime assert(T == i32); assert(data == 0); } diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index c718972537..33260a88df 100644 --- a/lib/std/array_list.zig +++ b/lib/std/array_list.zig @@ -40,7 +40,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { .allocator = allocator, }; } - + /// Initialize with capacity to hold at least num elements. /// Deinitialize with `deinit` or use `toOwnedSlice`. pub fn initCapacity(allocator: *Allocator, num: usize) !Self { diff --git a/lib/std/atomic/queue.zig b/lib/std/atomic/queue.zig index 63bacb4fb5..f5dbd04da7 100644 --- a/lib/std/atomic/queue.zig +++ b/lib/std/atomic/queue.zig @@ -106,7 +106,7 @@ pub fn Queue(comptime T: type) type { pub fn dump(self: *Self) void { var stderr_file = std.io.getStdErr() catch return; 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; } diff --git a/lib/std/atomic/stack.zig b/lib/std/atomic/stack.zig index 9de8e36f87..0f67a257cc 100644 --- a/lib/std/atomic/stack.zig +++ b/lib/std/atomic/stack.zig @@ -9,7 +9,7 @@ const expect = std.testing.expect; pub fn Stack(comptime T: type) type { return struct { root: ?*Node, - lock: @typeOf(lock_init), + lock: @TypeOf(lock_init), const lock_init = if (builtin.single_threaded) {} else @as(u8, 0); diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 04a83c39f3..69b9e894bb 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -1290,7 +1290,7 @@ pub const DwarfInfo = struct { try di.dwarf_seekable_stream.seekTo(this_unit_offset); 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; 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); 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; 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); 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 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_indirect => { 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); defer allocator.destroy(frame); return await @asyncCall(frame, {}, parseFormValue, allocator, in_stream, child_form_id, is_64); diff --git a/lib/std/event/group.zig b/lib/std/event/group.zig index d9076ef78d..2668096615 100644 --- a/lib/std/event/group.zig +++ b/lib/std/event/group.zig @@ -61,7 +61,7 @@ pub fn Group(comptime ReturnType: type) type { /// `func` must be async and have return type `ReturnType`. /// Thread-safe. 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); const node = try self.allocator.create(AllocStack.Node); errdefer self.allocator.destroy(node); diff --git a/lib/std/event/loop.zig b/lib/std/event/loop.zig index 3a6cced79b..e80266c640 100644 --- a/lib/std/event/loop.zig +++ b/lib/std/event/loop.zig @@ -42,7 +42,7 @@ pub const Loop = struct { }, else => {}, }; - pub const Overlapped = @typeOf(overlapped_init); + pub const Overlapped = @TypeOf(overlapped_init); pub const Id = enum { Basic, diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index f01510b02c..f4926ae8d7 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -80,7 +80,7 @@ fn peekIsAlign(comptime fmt: []const u8) bool { /// /// If a formatted user type contains a function of the type /// ``` -/// fn format(value: ?, comptime fmt: []const u8, options: std.fmt.FormatOptions, context: var, comptime Errors: type, output: fn (@typeOf(context), []const u8) Errors!void) Errors!void +/// fn format(value: ?, comptime fmt: []const u8, options: std.fmt.FormatOptions, context: var, comptime Errors: type, output: fn (@TypeOf(context), []const u8) Errors!void) Errors!void /// ``` /// with `?` being the type formatted, this function will be called instead of the default implementation. /// This allows user types to be formatted in a logical manner instead of dumping all fields of the type. @@ -89,7 +89,7 @@ fn peekIsAlign(comptime fmt: []const u8) bool { pub fn format( context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, comptime fmt: []const u8, args: var, ) Errors!void { @@ -320,17 +320,17 @@ pub fn formatType( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, max_depth: usize, ) Errors!void { 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 formatInt(@ptrToInt(value), 16, false, FormatOptions{}, context, Errors, output); return; } - const T = @typeOf(value); + const T = @TypeOf(value); switch (@typeInfo(T)) { .ComptimeInt, .Int, .Float => { return formatValue(value, fmt, options, context, Errors, output); @@ -478,7 +478,7 @@ fn formatValue( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { if (comptime std.mem.eql(u8, fmt, "B")) { return formatBytes(value, options, 1000, context, Errors, output); @@ -486,7 +486,7 @@ fn formatValue( return formatBytes(value, options, 1024, context, Errors, output); } - const T = @typeOf(value); + const T = @TypeOf(value); switch (@typeId(T)) { .Float => return formatFloatValue(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, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { comptime var radix = 10; 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); break :blk @as(Int, value); } else @@ -515,7 +515,7 @@ pub fn formatIntValue( radix = 10; uppercase = false; } 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); } else { @compileError("Cannot print integer that is larger than 8 bits as a ascii"); @@ -542,7 +542,7 @@ fn formatFloatValue( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "e")) { return formatFloatScientific(value, options, context, Errors, output); @@ -559,7 +559,7 @@ pub fn formatText( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { if (fmt.len == 0) { return output(context, bytes); @@ -580,7 +580,7 @@ pub fn formatAsciiChar( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { return output(context, @as(*const [1]u8, &c)[0..]); } @@ -590,7 +590,7 @@ pub fn formatBuf( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { try output(context, buf); @@ -610,7 +610,7 @@ pub fn formatFloatScientific( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { var x = @floatCast(f64, value); @@ -672,7 +672,7 @@ pub fn formatFloatScientific( try output(context, float_decimal.digits[0..1]); try output(context, "."); 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]); } else { @@ -705,7 +705,7 @@ pub fn formatFloatDecimal( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { var x = @as(f64, value); @@ -851,7 +851,7 @@ pub fn formatBytes( comptime radix: usize, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { if (value == 0) { return output(context, "0B"); @@ -892,15 +892,15 @@ pub fn formatInt( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) 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); break :blk @as(Int, value); } else value; - if (@typeOf(int_value).is_signed) { + if (@TypeOf(int_value).is_signed) { return formatIntSigned(int_value, base, uppercase, options, context, Errors, output); } else { return formatIntUnsigned(int_value, base, uppercase, options, context, Errors, output); @@ -914,7 +914,7 @@ fn formatIntSigned( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { const new_options = FormatOptions{ .width = if (options.width) |w| (if (w == 0) 0 else w - 1) else null, @@ -922,7 +922,7 @@ fn formatIntSigned( .fill = options.fill, }; - const uint = @IntType(false, @typeOf(value).bit_count); + const uint = @IntType(false, @TypeOf(value).bit_count); if (value < 0) { const minus_sign: u8 = '-'; try output(context, @as(*const [1]u8, &minus_sign)[0..]); @@ -945,12 +945,12 @@ fn formatIntUnsigned( options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { assert(base >= 2); - 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 MinInt = @IntType(@typeOf(value).is_signed, min_int_bits); + 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 MinInt = @IntType(@TypeOf(value).is_signed, min_int_bits); var a: MinInt = value; var index: usize = buf.len; @@ -1420,7 +1420,7 @@ test "custom" { options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { 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 }); @@ -1610,7 +1610,7 @@ test "formatIntValue with comptime_int" { const value: comptime_int = 123456789123456789; 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")); } @@ -1626,7 +1626,7 @@ test "formatType max_depth" { options: FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { if (fmt.len == 0) { 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; 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{ ... }")); 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) }")); 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) }")); 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) }")); } diff --git a/lib/std/hash/auto_hash.zig b/lib/std/hash/auto_hash.zig index 696a5e81dc..e60a1c1055 100644 --- a/lib/std/hash/auto_hash.zig +++ b/lib/std/hash/auto_hash.zig @@ -22,7 +22,7 @@ pub const HashStrategy = enum { /// Helper function to hash a pointer and mutate the strategy if needed. 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) { 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. /// Strategy is provided to determine if pointers should be followed or not. pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void { - const Key = @typeOf(key); + const Key = @TypeOf(key); switch (@typeInfo(Key)) { .NoReturn, .Opaque, @@ -164,7 +164,7 @@ pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void { /// Only hashes `key` itself, pointers are not followed. /// Slices are rejected to avoid ambiguity on the user's intention. pub fn autoHash(hasher: var, key: var) void { - const Key = @typeOf(key); + const Key = @TypeOf(key); if (comptime meta.trait.isSlice(Key)) { comptime assert(@hasDecl(std, "StringHashMap")); // detect when the following message needs updated const extra_help = if (Key == []const u8) diff --git a/lib/std/hash/cityhash.zig b/lib/std/hash/cityhash.zig index 0f78140c9d..18b3abe16d 100644 --- a/lib/std/hash/cityhash.zig +++ b/lib/std/hash/cityhash.zig @@ -360,9 +360,9 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 { var hashes: [hashbytes * 256]u8 = undefined; var final: [hashbytes]u8 = undefined; - @memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@typeOf(key))); - @memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@typeOf(hashes))); - @memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@typeOf(final))); + @memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@TypeOf(key))); + @memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@TypeOf(hashes))); + @memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@TypeOf(final))); var i: u32 = 0; 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); 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); } diff --git a/lib/std/hash/murmur.zig b/lib/std/hash/murmur.zig index 0163927010..f6c0ccafb3 100644 --- a/lib/std/hash/murmur.zig +++ b/lib/std/hash/murmur.zig @@ -285,9 +285,9 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 { var hashes: [hashbytes * 256]u8 = undefined; var final: [hashbytes]u8 = undefined; - @memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@typeOf(key))); - @memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@typeOf(hashes))); - @memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@typeOf(final))); + @memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@TypeOf(key))); + @memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@TypeOf(hashes))); + @memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@TypeOf(final))); var i: u32 = 0; 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); 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); } diff --git a/lib/std/http/headers.zig b/lib/std/http/headers.zig index 7cac6648de..e02a2187d6 100644 --- a/lib/std/http/headers.zig +++ b/lib/std/http/headers.zig @@ -367,7 +367,7 @@ pub const Headers = struct { options: std.fmt.FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { var it = self.iterator(); while (it.next()) |entry| { diff --git a/lib/std/io.zig b/lib/std/io.zig index 68c147a33c..c8635b8551 100644 --- a/lib/std/io.zig +++ b/lib/std/io.zig @@ -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 { if (bits == 0) return; - const U = @typeOf(value); + const U = @TypeOf(value); comptime assert(trait.isUnsignedInt(U)); //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` pub fn deserializeInto(self: *Self, ptr: var) !void { - const T = @typeOf(ptr); + const T = @TypeOf(ptr); comptime assert(trait.is(builtin.TypeId.Pointer)(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 { - const T = @typeOf(value); + const T = @TypeOf(value); comptime assert(trait.is(builtin.TypeId.Int)(T) or trait.is(builtin.TypeId.Float)(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 pub fn serialize(self: *Self, value: var) Error!void { - const T = comptime @typeOf(value); + const T = comptime @TypeOf(value); if (comptime trait.isIndexable(T)) { for (value) |v| diff --git a/lib/std/json.zig b/lib/std/json.zig index a02c4ca733..c1a0b42009 100644 --- a/lib/std/json.zig +++ b/lib/std/json.zig @@ -1038,7 +1038,7 @@ pub const Value = union(enum) { } 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.one_indent = ""; 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 { 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; try w.emitJson(self); } @@ -1338,7 +1338,7 @@ test "write json then parse it" { var slice_out_stream = std.io.SliceOutStream.init(&out_buffer); 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(); diff --git a/lib/std/json/write_stream.zig b/lib/std/json/write_stream.zig index 7cff613dad..51afe7fcbc 100644 --- a/lib/std/json/write_stream.zig +++ b/lib/std/json/write_stream.zig @@ -155,7 +155,7 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type { value: var, ) !void { assert(self.state[self.state_index] == State.Value); - switch (@typeInfo(@typeOf(value))) { + switch (@typeInfo(@TypeOf(value))) { .Int => |info| { if (info.bits < 53) { try self.stream.print("{}", .{value}); @@ -257,7 +257,7 @@ test "json write stream" { var mem_buf: [1024 * 10]u8 = undefined; 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)); const result = slice_stream.getWritten(); diff --git a/lib/std/math.zig b/lib/std/math.zig index f87996f174..b3b50beac6 100644 --- a/lib/std/math.zig +++ b/lib/std/math.zig @@ -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. pub fn forceEval(value: var) void { - const T = @typeOf(value); + const T = @TypeOf(value); switch (T) { f16 => { var x: f16 = undefined; @@ -239,13 +239,13 @@ pub fn Min(comptime A: type, comptime B: type) type { }, 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, /// the return type is the smaller type. -pub fn min(x: var, y: var) Min(@typeOf(x), @typeOf(y)) { - const Result = Min(@typeOf(x), @typeOf(y)); +pub fn min(x: var, y: var) Min(@TypeOf(x), @TypeOf(y)) { + const Result = Min(@TypeOf(x), @TypeOf(y)); if (x < y) { // 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. @@ -269,33 +269,33 @@ test "math.min" { var a: u16 = 999; var b: u32 = 10; var result = min(a, b); - testing.expect(@typeOf(result) == u16); + testing.expect(@TypeOf(result) == u16); testing.expect(result == 10); } { var a: f64 = 10.34; var b: f32 = 999.12; var result = min(a, b); - testing.expect(@typeOf(result) == f64); + testing.expect(@TypeOf(result) == f64); testing.expect(result == 10.34); } { var a: i8 = -127; var b: i16 = -200; var result = min(a, b); - testing.expect(@typeOf(result) == i16); + testing.expect(@TypeOf(result) == i16); testing.expect(result == -200); } { const a = 10.34; var b: f32 = 999.12; var result = min(a, b); - testing.expect(@typeOf(result) == f32); + testing.expect(@TypeOf(result) == f32); 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; } @@ -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; } -pub fn negate(x: var) !@typeOf(x) { - return sub(@typeOf(x), 0, x); +pub fn negate(x: var) !@TypeOf(x) { + return sub(@TypeOf(x), 0, x); } 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 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) { 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 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) { return a >> casted_shift_amt; } else { @@ -505,12 +505,12 @@ fn testOverflow() void { testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000); } -pub fn absInt(x: var) !@typeOf(x) { - const T = @typeOf(x); +pub fn absInt(x: var) !@TypeOf(x) { + const T = @TypeOf(x); 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 - if (x == minInt(@typeOf(x))) { + if (x == minInt(@TypeOf(x))) { return error.Overflow; } else { @setRuntimeSafety(false); @@ -654,16 +654,16 @@ fn testRem() void { /// Returns the absolute value of the integer parameter. /// Result is an unsigned integer. pub fn absCast(x: var) t: { - if (@typeOf(x) == comptime_int) { + if (@TypeOf(x) == comptime_int) { break :t comptime_int; } 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; } - const uint = @IntType(false, @typeOf(x).bit_count); + const uint = @IntType(false, @TypeOf(x).bit_count); if (x >= 0) return @intCast(uint, x); return @intCast(uint, -(x + 1)) + 1; @@ -671,23 +671,23 @@ pub fn absCast(x: var) t: { test "math.absCast" { 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(@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(@typeOf(absCast(@as(i32, minInt(i32)))) == u32); + testing.expect(@TypeOf(absCast(@as(i32, minInt(i32)))) == u32); testing.expect(absCast(-999) == 999); } /// Returns the negation of the integer parameter. /// Result is a signed integer. -pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) { - if (@typeOf(x).is_signed) return negate(x); +pub fn negateCast(x: var) !@IntType(true, @TypeOf(x).bit_count) { + 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 minInt(int); @@ -697,10 +697,10 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) { test "math.negateCast" { 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(@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))); } @@ -709,10 +709,10 @@ test "math.negateCast" { /// return an error. 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(@typeOf(x)) == builtin.TypeId.Int); // must pass an integer - if (maxInt(@typeOf(x)) > maxInt(T) and x > maxInt(T)) { + comptime assert(@typeId(@TypeOf(x)) == builtin.TypeId.Int); // must pass an integer + if (maxInt(@TypeOf(x)) > maxInt(T) and x > maxInt(T)) { 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; } else { return @intCast(T, x); @@ -726,13 +726,13 @@ test "math.cast" { testing.expectError(error.Overflow, cast(u64, @as(i8, -1))); 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}; /// 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); if (addr % alignment != 0) { return error.UnalignedMemory; @@ -858,7 +858,7 @@ test "std.math.log2_int_ceil" { } 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.Float => return @floatCast(T, value), builtin.TypeId.ComptimeInt => return @as(T, value), diff --git a/lib/std/math/acos.zig b/lib/std/math/acos.zig index 94b6fc3f8f..aec0d4706a 100644 --- a/lib/std/math/acos.zig +++ b/lib/std/math/acos.zig @@ -12,8 +12,8 @@ const expect = std.testing.expect; /// /// Special cases: /// - acos(x) = nan if x < -1 or x > 1 -pub fn acos(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn acos(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => acos32(x), f64 => acos64(x), diff --git a/lib/std/math/acosh.zig b/lib/std/math/acosh.zig index 065e4d39de..0f99335058 100644 --- a/lib/std/math/acosh.zig +++ b/lib/std/math/acosh.zig @@ -14,8 +14,8 @@ const expect = std.testing.expect; /// Special cases: /// - acosh(x) = snan if x < 1 /// - acosh(nan) = nan -pub fn acosh(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn acosh(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => acosh32(x), f64 => acosh64(x), diff --git a/lib/std/math/asin.zig b/lib/std/math/asin.zig index d354f8ceed..db57e2088f 100644 --- a/lib/std/math/asin.zig +++ b/lib/std/math/asin.zig @@ -13,8 +13,8 @@ const expect = std.testing.expect; /// Special Cases: /// - asin(+-0) = +-0 /// - asin(x) = nan if x < -1 or x > 1 -pub fn asin(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn asin(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => asin32(x), f64 => asin64(x), diff --git a/lib/std/math/asinh.zig b/lib/std/math/asinh.zig index b915df3171..ab1b650139 100644 --- a/lib/std/math/asinh.zig +++ b/lib/std/math/asinh.zig @@ -15,8 +15,8 @@ const maxInt = std.math.maxInt; /// - asinh(+-0) = +-0 /// - asinh(+-inf) = +-inf /// - asinh(nan) = nan -pub fn asinh(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn asinh(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => asinh32(x), f64 => asinh64(x), diff --git a/lib/std/math/atan.zig b/lib/std/math/atan.zig index ea639872be..eb9154b5fe 100644 --- a/lib/std/math/atan.zig +++ b/lib/std/math/atan.zig @@ -13,8 +13,8 @@ const expect = std.testing.expect; /// Special Cases: /// - atan(+-0) = +-0 /// - atan(+-inf) = +-pi/2 -pub fn atan(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn atan(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => atan32(x), f64 => atan64(x), diff --git a/lib/std/math/atanh.zig b/lib/std/math/atanh.zig index ae588f4fb8..e58a10fff5 100644 --- a/lib/std/math/atanh.zig +++ b/lib/std/math/atanh.zig @@ -15,8 +15,8 @@ const maxInt = std.math.maxInt; /// - atanh(+-1) = +-inf with signal /// - atanh(x) = nan if |x| > 1 with signal /// - atanh(nan) = nan -pub fn atanh(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn atanh(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => atanh_32(x), f64 => atanh_64(x), diff --git a/lib/std/math/big/int.zig b/lib/std/math/big/int.zig index 0d0b186332..ef83aceb2f 100644 --- a/lib/std/math/big/int.zig +++ b/lib/std/math/big/int.zig @@ -268,7 +268,7 @@ pub const Int = struct { /// Sets an Int to value. Value must be an primitive integer type. pub fn set(self: *Int, value: var) Allocator.Error!void { self.assertWritable(); - const T = @typeOf(value); + const T = @TypeOf(value); switch (@typeInfo(T)) { TypeId.Int => |info| { @@ -522,7 +522,7 @@ pub const Int = struct { options: std.fmt.FormatOptions, context: var, comptime FmtError: type, - output: fn (@typeOf(context), []const u8) FmtError!void, + output: fn (@TypeOf(context), []const u8) FmtError!void, ) FmtError!void { self.assertWritable(); // TODO look at fmt and support other bases diff --git a/lib/std/math/cbrt.zig b/lib/std/math/cbrt.zig index c9e205a495..2b219d5368 100644 --- a/lib/std/math/cbrt.zig +++ b/lib/std/math/cbrt.zig @@ -14,8 +14,8 @@ const expect = std.testing.expect; /// - cbrt(+-0) = +-0 /// - cbrt(+-inf) = +-inf /// - cbrt(nan) = nan -pub fn cbrt(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn cbrt(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => cbrt32(x), f64 => cbrt64(x), diff --git a/lib/std/math/ceil.zig b/lib/std/math/ceil.zig index b5a2238621..b94e13a176 100644 --- a/lib/std/math/ceil.zig +++ b/lib/std/math/ceil.zig @@ -15,8 +15,8 @@ const expect = std.testing.expect; /// - ceil(+-0) = +-0 /// - ceil(+-inf) = +-inf /// - ceil(nan) = nan -pub fn ceil(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn ceil(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => ceil32(x), f64 => ceil64(x), diff --git a/lib/std/math/complex/abs.zig b/lib/std/math/complex/abs.zig index 8105f57218..75b967f3d2 100644 --- a/lib/std/math/complex/abs.zig +++ b/lib/std/math/complex/abs.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the absolute value (modulus) of z. -pub fn abs(z: var) @typeOf(z.re) { - const T = @typeOf(z.re); +pub fn abs(z: var) @TypeOf(z.re) { + const T = @TypeOf(z.re); return math.hypot(T, z.re, z.im); } diff --git a/lib/std/math/complex/acos.zig b/lib/std/math/complex/acos.zig index b078ebf345..24a645375c 100644 --- a/lib/std/math/complex/acos.zig +++ b/lib/std/math/complex/acos.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the arc-cosine of z. -pub fn acos(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn acos(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); const q = cmath.asin(z); return Complex(T).new(@as(T, math.pi) / 2 - q.re, -q.im); } diff --git a/lib/std/math/complex/acosh.zig b/lib/std/math/complex/acosh.zig index 6f0fd2e36c..996334034a 100644 --- a/lib/std/math/complex/acosh.zig +++ b/lib/std/math/complex/acosh.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the hyperbolic arc-cosine of z. -pub fn acosh(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn acosh(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); const q = cmath.acos(z); return Complex(T).new(-q.im, q.re); } diff --git a/lib/std/math/complex/arg.zig b/lib/std/math/complex/arg.zig index d0c9588b8d..f690e92143 100644 --- a/lib/std/math/complex/arg.zig +++ b/lib/std/math/complex/arg.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the angular component (in radians) of z. -pub fn arg(z: var) @typeOf(z.re) { - const T = @typeOf(z.re); +pub fn arg(z: var) @TypeOf(z.re) { + const T = @TypeOf(z.re); return math.atan2(T, z.im, z.re); } diff --git a/lib/std/math/complex/asin.zig b/lib/std/math/complex/asin.zig index 76f94a286c..01fa33156a 100644 --- a/lib/std/math/complex/asin.zig +++ b/lib/std/math/complex/asin.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; // Returns the arc-sine of z. -pub fn asin(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn asin(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); const x = z.re; const y = z.im; diff --git a/lib/std/math/complex/asinh.zig b/lib/std/math/complex/asinh.zig index da065aad01..47d8244adb 100644 --- a/lib/std/math/complex/asinh.zig +++ b/lib/std/math/complex/asinh.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the hyperbolic arc-sine of z. -pub fn asinh(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn asinh(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); const q = Complex(T).new(-z.im, z.re); const r = cmath.asin(q); return Complex(T).new(r.im, -r.re); diff --git a/lib/std/math/complex/atan.zig b/lib/std/math/complex/atan.zig index 3cd19961c8..d5e3dcac73 100644 --- a/lib/std/math/complex/atan.zig +++ b/lib/std/math/complex/atan.zig @@ -12,8 +12,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the arc-tangent of z. -pub fn atan(z: var) @typeOf(z) { - const T = @typeOf(z.re); +pub fn atan(z: var) @TypeOf(z) { + const T = @TypeOf(z.re); return switch (T) { f32 => atan32(z), f64 => atan64(z), diff --git a/lib/std/math/complex/atanh.zig b/lib/std/math/complex/atanh.zig index 225e7c61de..8b70306224 100644 --- a/lib/std/math/complex/atanh.zig +++ b/lib/std/math/complex/atanh.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the hyperbolic arc-tangent of z. -pub fn atanh(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn atanh(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); const q = Complex(T).new(-z.im, z.re); const r = cmath.atan(q); return Complex(T).new(r.im, -r.re); diff --git a/lib/std/math/complex/conj.zig b/lib/std/math/complex/conj.zig index bd71ca3c06..1065d4bb73 100644 --- a/lib/std/math/complex/conj.zig +++ b/lib/std/math/complex/conj.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the complex conjugate of z. -pub fn conj(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn conj(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); return Complex(T).new(z.re, -z.im); } diff --git a/lib/std/math/complex/cos.zig b/lib/std/math/complex/cos.zig index 332009ffe5..1aefa73db5 100644 --- a/lib/std/math/complex/cos.zig +++ b/lib/std/math/complex/cos.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the cosine of z. -pub fn cos(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn cos(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); const p = Complex(T).new(-z.im, z.re); return cmath.cosh(p); } diff --git a/lib/std/math/complex/cosh.zig b/lib/std/math/complex/cosh.zig index 89afcac42e..ce2c78b455 100644 --- a/lib/std/math/complex/cosh.zig +++ b/lib/std/math/complex/cosh.zig @@ -14,8 +14,8 @@ const Complex = cmath.Complex; const ldexp_cexp = @import("ldexp.zig").ldexp_cexp; /// Returns the hyperbolic arc-cosine of z. -pub fn cosh(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn cosh(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); return switch (T) { f32 => cosh32(z), f64 => cosh64(z), diff --git a/lib/std/math/complex/exp.zig b/lib/std/math/complex/exp.zig index 5cd1cb4ed6..b39875c770 100644 --- a/lib/std/math/complex/exp.zig +++ b/lib/std/math/complex/exp.zig @@ -14,8 +14,8 @@ const Complex = cmath.Complex; const ldexp_cexp = @import("ldexp.zig").ldexp_cexp; /// Returns e raised to the power of z (e^z). -pub fn exp(z: var) @typeOf(z) { - const T = @typeOf(z.re); +pub fn exp(z: var) @TypeOf(z) { + const T = @TypeOf(z.re); return switch (T) { f32 => exp32(z), diff --git a/lib/std/math/complex/ldexp.zig b/lib/std/math/complex/ldexp.zig index d5d4cc64a6..9eccd4bb98 100644 --- a/lib/std/math/complex/ldexp.zig +++ b/lib/std/math/complex/ldexp.zig @@ -11,8 +11,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns exp(z) scaled to avoid overflow. -pub fn ldexp_cexp(z: var, expt: i32) @typeOf(z) { - const T = @typeOf(z.re); +pub fn ldexp_cexp(z: var, expt: i32) @TypeOf(z) { + const T = @TypeOf(z.re); return switch (T) { f32 => ldexp_cexp32(z, expt), diff --git a/lib/std/math/complex/log.zig b/lib/std/math/complex/log.zig index 762b4fde9a..f1fad3175e 100644 --- a/lib/std/math/complex/log.zig +++ b/lib/std/math/complex/log.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the natural logarithm of z. -pub fn log(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn log(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); const r = cmath.abs(z); const phi = cmath.arg(z); diff --git a/lib/std/math/complex/proj.zig b/lib/std/math/complex/proj.zig index c8f2d9fc6d..349f6b3abb 100644 --- a/lib/std/math/complex/proj.zig +++ b/lib/std/math/complex/proj.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the projection of z onto the riemann sphere. -pub fn proj(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn proj(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); if (math.isInf(z.re) or math.isInf(z.im)) { return Complex(T).new(math.inf(T), math.copysign(T, 0, z.re)); diff --git a/lib/std/math/complex/sin.zig b/lib/std/math/complex/sin.zig index 9ddc3a7a80..87dc57911b 100644 --- a/lib/std/math/complex/sin.zig +++ b/lib/std/math/complex/sin.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the sine of z. -pub fn sin(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn sin(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); const p = Complex(T).new(-z.im, z.re); const q = cmath.sinh(p); return Complex(T).new(q.im, -q.re); diff --git a/lib/std/math/complex/sinh.zig b/lib/std/math/complex/sinh.zig index 0b1294bb6a..d633bcc37e 100644 --- a/lib/std/math/complex/sinh.zig +++ b/lib/std/math/complex/sinh.zig @@ -14,8 +14,8 @@ const Complex = cmath.Complex; const ldexp_cexp = @import("ldexp.zig").ldexp_cexp; /// Returns the hyperbolic sine of z. -pub fn sinh(z: var) @typeOf(z) { - const T = @typeOf(z.re); +pub fn sinh(z: var) @TypeOf(z) { + const T = @TypeOf(z.re); return switch (T) { f32 => sinh32(z), f64 => sinh64(z), diff --git a/lib/std/math/complex/sqrt.zig b/lib/std/math/complex/sqrt.zig index 7e17f422bb..57e73f6cd1 100644 --- a/lib/std/math/complex/sqrt.zig +++ b/lib/std/math/complex/sqrt.zig @@ -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 /// as the imaginary part of z. -pub fn sqrt(z: var) @typeOf(z) { - const T = @typeOf(z.re); +pub fn sqrt(z: var) @TypeOf(z) { + const T = @TypeOf(z.re); return switch (T) { f32 => sqrt32(z), diff --git a/lib/std/math/complex/tan.zig b/lib/std/math/complex/tan.zig index 398b8295ca..70304803db 100644 --- a/lib/std/math/complex/tan.zig +++ b/lib/std/math/complex/tan.zig @@ -5,8 +5,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the tanget of z. -pub fn tan(z: var) Complex(@typeOf(z.re)) { - const T = @typeOf(z.re); +pub fn tan(z: var) Complex(@TypeOf(z.re)) { + const T = @TypeOf(z.re); const q = Complex(T).new(-z.im, z.re); const r = cmath.tanh(q); return Complex(T).new(r.im, -r.re); diff --git a/lib/std/math/complex/tanh.zig b/lib/std/math/complex/tanh.zig index fc7f4e9ea8..3249a4309d 100644 --- a/lib/std/math/complex/tanh.zig +++ b/lib/std/math/complex/tanh.zig @@ -12,8 +12,8 @@ const cmath = math.complex; const Complex = cmath.Complex; /// Returns the hyperbolic tangent of z. -pub fn tanh(z: var) @typeOf(z) { - const T = @typeOf(z.re); +pub fn tanh(z: var) @TypeOf(z) { + const T = @TypeOf(z.re); return switch (T) { f32 => tanh32(z), f64 => tanh64(z), diff --git a/lib/std/math/cos.zig b/lib/std/math/cos.zig index 68e13e41bf..66a1cc8509 100644 --- a/lib/std/math/cos.zig +++ b/lib/std/math/cos.zig @@ -13,8 +13,8 @@ const expect = std.testing.expect; /// Special Cases: /// - cos(+-inf) = nan /// - cos(nan) = nan -pub fn cos(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn cos(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => cos_(f32, x), f64 => cos_(f64, x), diff --git a/lib/std/math/cosh.zig b/lib/std/math/cosh.zig index 62bedeaa49..17c291d947 100644 --- a/lib/std/math/cosh.zig +++ b/lib/std/math/cosh.zig @@ -17,8 +17,8 @@ const maxInt = std.math.maxInt; /// - cosh(+-0) = 1 /// - cosh(+-inf) = +inf /// - cosh(nan) = nan -pub fn cosh(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn cosh(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => cosh32(x), f64 => cosh64(x), diff --git a/lib/std/math/exp.zig b/lib/std/math/exp.zig index 986c35bf0d..da80b201c0 100644 --- a/lib/std/math/exp.zig +++ b/lib/std/math/exp.zig @@ -14,8 +14,8 @@ const builtin = @import("builtin"); /// Special Cases: /// - exp(+inf) = +inf /// - exp(nan) = nan -pub fn exp(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn exp(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => exp32(x), f64 => exp64(x), diff --git a/lib/std/math/exp2.zig b/lib/std/math/exp2.zig index f3e51e542e..411f789187 100644 --- a/lib/std/math/exp2.zig +++ b/lib/std/math/exp2.zig @@ -13,8 +13,8 @@ const expect = std.testing.expect; /// Special Cases: /// - exp2(+inf) = +inf /// - exp2(nan) = nan -pub fn exp2(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn exp2(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => exp2_32(x), f64 => exp2_64(x), diff --git a/lib/std/math/expm1.zig b/lib/std/math/expm1.zig index 871fa38449..91752e9f80 100644 --- a/lib/std/math/expm1.zig +++ b/lib/std/math/expm1.zig @@ -18,8 +18,8 @@ const expect = std.testing.expect; /// - expm1(+inf) = +inf /// - expm1(-inf) = -1 /// - expm1(nan) = nan -pub fn expm1(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn expm1(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => expm1_32(x), f64 => expm1_64(x), diff --git a/lib/std/math/expo2.zig b/lib/std/math/expo2.zig index 590f36bb18..e70e365f26 100644 --- a/lib/std/math/expo2.zig +++ b/lib/std/math/expo2.zig @@ -7,8 +7,8 @@ const math = @import("../math.zig"); /// Returns exp(x) / 2 for x >= log(maxFloat(T)). -pub fn expo2(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn expo2(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => expo2f(x), f64 => expo2d(x), diff --git a/lib/std/math/fabs.zig b/lib/std/math/fabs.zig index e0eadd0d00..a659e35ca2 100644 --- a/lib/std/math/fabs.zig +++ b/lib/std/math/fabs.zig @@ -14,8 +14,8 @@ const maxInt = std.math.maxInt; /// Special Cases: /// - fabs(+-inf) = +inf /// - fabs(nan) = nan -pub fn fabs(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn fabs(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f16 => fabs16(x), f32 => fabs32(x), diff --git a/lib/std/math/floor.zig b/lib/std/math/floor.zig index f2cabe8f02..1eda362e69 100644 --- a/lib/std/math/floor.zig +++ b/lib/std/math/floor.zig @@ -15,8 +15,8 @@ const math = std.math; /// - floor(+-0) = +-0 /// - floor(+-inf) = +-inf /// - floor(nan) = nan -pub fn floor(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn floor(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f16 => floor16(x), f32 => floor32(x), diff --git a/lib/std/math/frexp.zig b/lib/std/math/frexp.zig index 93705ae6a4..cfdf9f838d 100644 --- a/lib/std/math/frexp.zig +++ b/lib/std/math/frexp.zig @@ -24,8 +24,8 @@ pub const frexp64_result = frexp_result(f64); /// - frexp(+-0) = +-0, 0 /// - frexp(+-inf) = +-inf, 0 /// - frexp(nan) = nan, undefined -pub fn frexp(x: var) frexp_result(@typeOf(x)) { - const T = @typeOf(x); +pub fn frexp(x: var) frexp_result(@TypeOf(x)) { + const T = @TypeOf(x); return switch (T) { f32 => frexp32(x), f64 => frexp64(x), diff --git a/lib/std/math/ilogb.zig b/lib/std/math/ilogb.zig index 8d23bb09a0..22e3fbaa97 100644 --- a/lib/std/math/ilogb.zig +++ b/lib/std/math/ilogb.zig @@ -17,7 +17,7 @@ const minInt = std.math.minInt; /// - ilogb(0) = maxInt(i32) /// - ilogb(nan) = maxInt(i32) pub fn ilogb(x: var) i32 { - const T = @typeOf(x); + const T = @TypeOf(x); return switch (T) { f32 => ilogb32(x), f64 => ilogb64(x), diff --git a/lib/std/math/isfinite.zig b/lib/std/math/isfinite.zig index 3d23a0f3bf..26b3ce54a1 100644 --- a/lib/std/math/isfinite.zig +++ b/lib/std/math/isfinite.zig @@ -5,7 +5,7 @@ const maxInt = std.math.maxInt; /// Returns whether x is a finite value. pub fn isFinite(x: var) bool { - const T = @typeOf(x); + const T = @TypeOf(x); switch (T) { f16 => { const bits = @bitCast(u16, x); diff --git a/lib/std/math/isinf.zig b/lib/std/math/isinf.zig index d691068be5..6eacab52ad 100644 --- a/lib/std/math/isinf.zig +++ b/lib/std/math/isinf.zig @@ -5,7 +5,7 @@ const maxInt = std.math.maxInt; /// Returns whether x is an infinity, ignoring sign. pub fn isInf(x: var) bool { - const T = @typeOf(x); + const T = @TypeOf(x); switch (T) { f16 => { 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. pub fn isPositiveInf(x: var) bool { - const T = @typeOf(x); + const T = @TypeOf(x); switch (T) { f16 => { 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. pub fn isNegativeInf(x: var) bool { - const T = @typeOf(x); + const T = @TypeOf(x); switch (T) { f16 => { return @bitCast(u16, x) == 0xFC00; diff --git a/lib/std/math/isnormal.zig b/lib/std/math/isnormal.zig index 01d919d417..917b4ebfcf 100644 --- a/lib/std/math/isnormal.zig +++ b/lib/std/math/isnormal.zig @@ -5,7 +5,7 @@ const maxInt = std.math.maxInt; // Returns whether x has a normalized representation (i.e. integer part of mantissa is 1). pub fn isNormal(x: var) bool { - const T = @typeOf(x); + const T = @TypeOf(x); switch (T) { f16 => { const bits = @bitCast(u16, x); diff --git a/lib/std/math/ln.zig b/lib/std/math/ln.zig index fd5741a818..f9bf03f83d 100644 --- a/lib/std/math/ln.zig +++ b/lib/std/math/ln.zig @@ -17,11 +17,11 @@ const TypeId = builtin.TypeId; /// - ln(0) = -inf /// - ln(x) = nan if x < 0 /// - ln(nan) = nan -pub fn ln(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn ln(x: var) @TypeOf(x) { + const T = @TypeOf(x); switch (@typeId(T)) { TypeId.ComptimeFloat => { - return @typeOf(1.0)(ln_64(x)); + return @TypeOf(1.0)(ln_64(x)); }, TypeId.Float => { return switch (T) { @@ -31,7 +31,7 @@ pub fn ln(x: var) @typeOf(x) { }; }, TypeId.ComptimeInt => { - return @typeOf(1)(math.floor(ln_64(@as(f64, x)))); + return @TypeOf(1)(math.floor(ln_64(@as(f64, x)))); }, TypeId.Int => { return @as(T, math.floor(ln_64(@as(f64, x)))); diff --git a/lib/std/math/log.zig b/lib/std/math/log.zig index 40b716b005..1302b564b6 100644 --- a/lib/std/math/log.zig +++ b/lib/std/math/log.zig @@ -23,10 +23,10 @@ pub fn log(comptime T: type, base: T, x: T) T { const float_base = math.lossyCast(f64, base); switch (@typeId(T)) { 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 => { - 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 => { // TODO implement integer log without using float math diff --git a/lib/std/math/log10.zig b/lib/std/math/log10.zig index f895e102a0..873b33bdbe 100644 --- a/lib/std/math/log10.zig +++ b/lib/std/math/log10.zig @@ -18,11 +18,11 @@ const maxInt = std.math.maxInt; /// - log10(0) = -inf /// - log10(x) = nan if x < 0 /// - log10(nan) = nan -pub fn log10(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn log10(x: var) @TypeOf(x) { + const T = @TypeOf(x); switch (@typeId(T)) { TypeId.ComptimeFloat => { - return @typeOf(1.0)(log10_64(x)); + return @TypeOf(1.0)(log10_64(x)); }, TypeId.Float => { return switch (T) { @@ -32,7 +32,7 @@ pub fn log10(x: var) @typeOf(x) { }; }, TypeId.ComptimeInt => { - return @typeOf(1)(math.floor(log10_64(@as(f64, x)))); + return @TypeOf(1)(math.floor(log10_64(@as(f64, x)))); }, TypeId.Int => { return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x)))); diff --git a/lib/std/math/log1p.zig b/lib/std/math/log1p.zig index 047e089a91..5e92cfdea3 100644 --- a/lib/std/math/log1p.zig +++ b/lib/std/math/log1p.zig @@ -17,8 +17,8 @@ const expect = std.testing.expect; /// - log1p(-1) = -inf /// - log1p(x) = nan if x < -1 /// - log1p(nan) = nan -pub fn log1p(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn log1p(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => log1p_32(x), f64 => log1p_64(x), diff --git a/lib/std/math/log2.zig b/lib/std/math/log2.zig index 47b214d6cf..bf052db59b 100644 --- a/lib/std/math/log2.zig +++ b/lib/std/math/log2.zig @@ -18,11 +18,11 @@ const maxInt = std.math.maxInt; /// - log2(0) = -inf /// - log2(x) = nan if x < 0 /// - log2(nan) = nan -pub fn log2(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn log2(x: var) @TypeOf(x) { + const T = @TypeOf(x); switch (@typeId(T)) { TypeId.ComptimeFloat => { - return @typeOf(1.0)(log2_64(x)); + return @TypeOf(1.0)(log2_64(x)); }, TypeId.Float => { return switch (T) { diff --git a/lib/std/math/modf.zig b/lib/std/math/modf.zig index 6567cbc9ed..6fd89e3dda 100644 --- a/lib/std/math/modf.zig +++ b/lib/std/math/modf.zig @@ -24,8 +24,8 @@ pub const modf64_result = modf_result(f64); /// Special Cases: /// - modf(+-inf) = +-inf, nan /// - modf(nan) = nan, nan -pub fn modf(x: var) modf_result(@typeOf(x)) { - const T = @typeOf(x); +pub fn modf(x: var) modf_result(@TypeOf(x)) { + const T = @TypeOf(x); return switch (T) { f32 => modf32(x), f64 => modf64(x), diff --git a/lib/std/math/round.zig b/lib/std/math/round.zig index adedbf2e94..dceb3ed770 100644 --- a/lib/std/math/round.zig +++ b/lib/std/math/round.zig @@ -15,8 +15,8 @@ const math = std.math; /// - round(+-0) = +-0 /// - round(+-inf) = +-inf /// - round(nan) = nan -pub fn round(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn round(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => round32(x), f64 => round64(x), diff --git a/lib/std/math/scalbn.zig b/lib/std/math/scalbn.zig index e3c457ade5..bab109f334 100644 --- a/lib/std/math/scalbn.zig +++ b/lib/std/math/scalbn.zig @@ -9,8 +9,8 @@ const math = std.math; const expect = std.testing.expect; /// Returns x * 2^n. -pub fn scalbn(x: var, n: i32) @typeOf(x) { - const T = @typeOf(x); +pub fn scalbn(x: var, n: i32) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => scalbn32(x, n), f64 => scalbn64(x, n), diff --git a/lib/std/math/signbit.zig b/lib/std/math/signbit.zig index f20753f2ff..9cb62b5042 100644 --- a/lib/std/math/signbit.zig +++ b/lib/std/math/signbit.zig @@ -4,7 +4,7 @@ const expect = std.testing.expect; /// Returns whether x is negative or negative 0. pub fn signbit(x: var) bool { - const T = @typeOf(x); + const T = @TypeOf(x); return switch (T) { f16 => signbit16(x), f32 => signbit32(x), diff --git a/lib/std/math/sin.zig b/lib/std/math/sin.zig index 3baa730123..5b92fd454b 100644 --- a/lib/std/math/sin.zig +++ b/lib/std/math/sin.zig @@ -14,8 +14,8 @@ const expect = std.testing.expect; /// - sin(+-0) = +-0 /// - sin(+-inf) = nan /// - sin(nan) = nan -pub fn sin(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn sin(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => sin_(T, x), f64 => sin_(T, x), diff --git a/lib/std/math/sinh.zig b/lib/std/math/sinh.zig index c9718e3ce2..e9c76cd509 100644 --- a/lib/std/math/sinh.zig +++ b/lib/std/math/sinh.zig @@ -17,8 +17,8 @@ const maxInt = std.math.maxInt; /// - sinh(+-0) = +-0 /// - sinh(+-inf) = +-inf /// - sinh(nan) = nan -pub fn sinh(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn sinh(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => sinh32(x), f64 => sinh64(x), diff --git a/lib/std/math/sqrt.zig b/lib/std/math/sqrt.zig index 89eda4ea2b..17c7003af1 100644 --- a/lib/std/math/sqrt.zig +++ b/lib/std/math/sqrt.zig @@ -12,8 +12,8 @@ const maxInt = std.math.maxInt; /// - sqrt(+-0) = +-0 /// - sqrt(x) = nan if x < 0 /// - sqrt(nan) = nan -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); +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); switch (@typeId(T)) { TypeId.ComptimeFloat => return @as(T, @sqrt(f64, x)), // TODO upgrade to f128 TypeId.Float => return @sqrt(T, x), diff --git a/lib/std/math/tan.zig b/lib/std/math/tan.zig index 1a027cf403..14272a48e2 100644 --- a/lib/std/math/tan.zig +++ b/lib/std/math/tan.zig @@ -14,8 +14,8 @@ const expect = std.testing.expect; /// - tan(+-0) = +-0 /// - tan(+-inf) = nan /// - tan(nan) = nan -pub fn tan(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn tan(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => tan_(f32, x), f64 => tan_(f64, x), diff --git a/lib/std/math/tanh.zig b/lib/std/math/tanh.zig index ced5f58bcc..1cad399729 100644 --- a/lib/std/math/tanh.zig +++ b/lib/std/math/tanh.zig @@ -17,8 +17,8 @@ const maxInt = std.math.maxInt; /// - sinh(+-0) = +-0 /// - sinh(+-inf) = +-1 /// - sinh(nan) = nan -pub fn tanh(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn tanh(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => tanh32(x), f64 => tanh64(x), diff --git a/lib/std/math/trunc.zig b/lib/std/math/trunc.zig index 56a842345c..b70f0c6be3 100644 --- a/lib/std/math/trunc.zig +++ b/lib/std/math/trunc.zig @@ -15,8 +15,8 @@ const maxInt = std.math.maxInt; /// - trunc(+-0) = +-0 /// - trunc(+-inf) = +-inf /// - trunc(nan) = nan -pub fn trunc(x: var) @typeOf(x) { - const T = @typeOf(x); +pub fn trunc(x: var) @TypeOf(x) { + const T = @TypeOf(x); return switch (T) { f32 => trunc32(x), f64 => trunc64(x), diff --git a/lib/std/mem.zig b/lib/std/mem.zig index cba1f9f177..8082d31063 100644 --- a/lib/std/mem.zig +++ b/lib/std/mem.zig @@ -86,7 +86,7 @@ pub const Allocator = struct { /// `ptr` should be the return value of `create`, or otherwise /// have the same address and alignment property. pub fn destroy(self: *Allocator, ptr: var) void { - const T = @typeOf(ptr).Child; + const T = @TypeOf(ptr).Child; if (@sizeOf(T) == 0) return; const non_const_ptr = @intToPtr([*]u8, @ptrToInt(ptr)); 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 `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: { - const Slice = @typeInfo(@typeOf(old_mem)).Pointer; + const Slice = @typeInfo(@TypeOf(old_mem)).Pointer; 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); } @@ -162,8 +162,8 @@ pub const Allocator = struct { old_mem: var, comptime new_alignment: u29, new_n: usize, - ) Error![]align(new_alignment) @typeInfo(@typeOf(old_mem)).Pointer.child { - const Slice = @typeInfo(@typeOf(old_mem)).Pointer; + ) Error![]align(new_alignment) @typeInfo(@TypeOf(old_mem)).Pointer.child { + const Slice = @typeInfo(@TypeOf(old_mem)).Pointer; const T = Slice.child; if (old_mem.len == 0) { return self.alignedAlloc(T, new_alignment, new_n); @@ -189,10 +189,10 @@ pub const Allocator = struct { /// Returned slice has same alignment as old_mem. /// Shrinking to 0 is the same as calling `free`. 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; } { - 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); } @@ -204,8 +204,8 @@ pub const Allocator = struct { old_mem: var, comptime new_alignment: u29, new_n: usize, - ) []align(new_alignment) @typeInfo(@typeOf(old_mem)).Pointer.child { - const Slice = @typeInfo(@typeOf(old_mem)).Pointer; + ) []align(new_alignment) @typeInfo(@TypeOf(old_mem)).Pointer.child { + const Slice = @typeInfo(@TypeOf(old_mem)).Pointer; const T = Slice.child; if (new_n == 0) { @@ -229,7 +229,7 @@ pub const Allocator = struct { /// Free an array allocated with `alloc`. To free a single item, /// see `destroy`. pub fn free(self: *Allocator, memory: var) void { - const Slice = @typeInfo(@typeOf(memory)).Pointer; + const Slice = @typeInfo(@TypeOf(memory)).Pointer; const bytes = @sliceToBytes(memory); if (bytes.len == 0) return; 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. -pub fn asBytes(ptr: var) AsBytesReturnType(@typeOf(ptr)) { - const P = @typeOf(ptr); +pub fn asBytes(ptr: var) AsBytesReturnType(@TypeOf(ptr)) { + const P = @TypeOf(ptr); return @ptrCast(AsBytesReturnType(P), ptr); } @@ -1363,7 +1363,7 @@ test "asBytes" { } ///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).*; } @@ -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 /// backed by those bytes, preserving constness. -pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @typeOf(bytes)) { - return @ptrCast(BytesAsValueReturnType(T, @typeOf(bytes)), bytes); +pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @TypeOf(bytes)) { + return @ptrCast(BytesAsValueReturnType(T, @TypeOf(bytes)), bytes); } 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. -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); - const ReturnType = SubArrayPtrReturnType(@typeOf(ptr), length); - const T = meta.Child(meta.Child(@typeOf(ptr))); + const ReturnType = SubArrayPtrReturnType(@TypeOf(ptr), length); + const T = meta.Child(meta.Child(@TypeOf(ptr))); return @ptrCast(ReturnType, &ptr[start]); } diff --git a/lib/std/meta.zig b/lib/std/meta.zig index 2352c0bfff..e0ddbed274 100644 --- a/lib/std/meta.zig +++ b/lib/std/meta.zig @@ -11,7 +11,7 @@ const TypeId = builtin.TypeId; const TypeInfo = builtin.TypeInfo; pub fn tagName(v: var) []const u8 { - const T = @typeOf(v); + const T = @TypeOf(v); switch (@typeInfo(T)) { TypeId.ErrorSet => return @errorName(v), else => return @tagName(v), @@ -339,8 +339,8 @@ test "std.meta.TagType" { } ///Returns the active tag of a tagged union -pub fn activeTag(u: var) @TagType(@typeOf(u)) { - const T = @typeOf(u); +pub fn activeTag(u: var) @TagType(@TypeOf(u)) { + const T = @TypeOf(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 /// field corresponding to the enum tag. 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.Enum)(Tag)); @@ -386,13 +386,13 @@ test "std.meta.TagPayloadType" { }; const MovedEvent = TagPayloadType(Event, Event.Moved); 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, /// where possible. Pointers are not followed. -pub fn eql(a: var, b: @typeOf(a)) bool { - const T = @typeOf(a); +pub fn eql(a: var, b: @TypeOf(a)) bool { + const T = @TypeOf(a); switch (@typeId(T)) { builtin.TypeId.Struct => { diff --git a/lib/std/meta/trait.zig b/lib/std/meta/trait.zig index 5da6e464b6..f36f3e15f0 100644 --- a/lib/std/meta/trait.zig +++ b/lib/std/meta/trait.zig @@ -13,7 +13,7 @@ fn traitFnWorkaround(comptime T: type) bool { return false; } -pub const TraitFn = @typeOf(traitFnWorkaround); +pub const TraitFn = @TypeOf(traitFnWorkaround); /// //////Trait generators @@ -61,7 +61,7 @@ pub fn hasFn(comptime name: []const u8) TraitFn { pub fn trait(comptime T: type) bool { if (!comptime isContainer(T)) 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); return decl_type_id == builtin.TypeId.Fn; } @@ -236,9 +236,9 @@ pub fn isSingleItemPtr(comptime T: type) bool { test "std.meta.trait.isSingleItemPtr" { const array = [_]u8{0} ** 10; - testing.expect(isSingleItemPtr(@typeOf(&array[0]))); - testing.expect(!isSingleItemPtr(@typeOf(array))); - testing.expect(!isSingleItemPtr(@typeOf(array[0..1]))); + testing.expect(isSingleItemPtr(@TypeOf(&array[0]))); + testing.expect(!isSingleItemPtr(@TypeOf(array))); + testing.expect(!isSingleItemPtr(@TypeOf(array[0..1]))); } /// @@ -253,9 +253,9 @@ pub fn isManyItemPtr(comptime T: type) bool { test "std.meta.trait.isManyItemPtr" { const array = [_]u8{0} ** 10; const mip = @ptrCast([*]const u8, &array[0]); - testing.expect(isManyItemPtr(@typeOf(mip))); - testing.expect(!isManyItemPtr(@typeOf(array))); - testing.expect(!isManyItemPtr(@typeOf(array[0..1]))); + testing.expect(isManyItemPtr(@TypeOf(mip))); + testing.expect(!isManyItemPtr(@TypeOf(array))); + testing.expect(!isManyItemPtr(@TypeOf(array[0..1]))); } /// @@ -269,9 +269,9 @@ pub fn isSlice(comptime T: type) bool { test "std.meta.trait.isSlice" { const array = [_]u8{0} ** 10; - testing.expect(isSlice(@typeOf(array[0..]))); - testing.expect(!isSlice(@typeOf(array))); - testing.expect(!isSlice(@typeOf(&array[0]))); + testing.expect(isSlice(@TypeOf(array[0..]))); + testing.expect(!isSlice(@TypeOf(array))); + testing.expect(!isSlice(@TypeOf(&array[0]))); } /// @@ -291,10 +291,10 @@ test "std.meta.trait.isIndexable" { const array = [_]u8{0} ** 10; const slice = array[0..]; - testing.expect(isIndexable(@typeOf(array))); - testing.expect(isIndexable(@typeOf(&array))); - testing.expect(isIndexable(@typeOf(slice))); - testing.expect(!isIndexable(meta.Child(@typeOf(slice)))); + testing.expect(isIndexable(@TypeOf(array))); + testing.expect(isIndexable(@TypeOf(&array))); + testing.expect(isIndexable(@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(f32)); testing.expect(isNumber(u64)); - testing.expect(isNumber(@typeOf(102))); - testing.expect(isNumber(@typeOf(102.123))); + testing.expect(isNumber(@TypeOf(102))); + testing.expect(isNumber(@TypeOf(102.123))); testing.expect(!isNumber([]u8)); testing.expect(!isNumber(NotANumber)); } @@ -328,10 +328,10 @@ pub fn isConstPtr(comptime T: type) bool { test "std.meta.trait.isConstPtr" { var t = @as(u8, 0); const c = @as(u8, 0); - testing.expect(isConstPtr(*const @typeOf(t))); - testing.expect(isConstPtr(@typeOf(&c))); - testing.expect(!isConstPtr(*@typeOf(t))); - testing.expect(!isConstPtr(@typeOf(6))); + testing.expect(isConstPtr(*const @TypeOf(t))); + testing.expect(isConstPtr(@TypeOf(&c))); + testing.expect(!isConstPtr(*@TypeOf(t))); + testing.expect(!isConstPtr(@TypeOf(6))); } pub fn isContainer(comptime T: type) bool { diff --git a/lib/std/mutex.zig b/lib/std/mutex.zig index 39cfab19ce..71188054f3 100644 --- a/lib/std/mutex.zig +++ b/lib/std/mutex.zig @@ -11,7 +11,7 @@ const ResetEvent = std.ResetEvent; /// no-ops. In single threaded debug mode, there is deadlock detection. pub const Mutex = if (builtin.single_threaded) struct { - lock: @typeOf(lock_init), + lock: @TypeOf(lock_init), const lock_init = if (std.debug.runtime_safety) false else {}; diff --git a/lib/std/net.zig b/lib/std/net.zig index a3f9c1c6d1..0a98bd999b 100644 --- a/lib/std/net.zig +++ b/lib/std/net.zig @@ -271,7 +271,7 @@ pub const Address = extern union { options: std.fmt.FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) !void { switch (self.any.family) { os.AF_INET => { diff --git a/lib/std/os.zig b/lib/std/os.zig index 8d6c7dd05e..04de59d6e1 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -2974,7 +2974,7 @@ pub fn res_mkquery( // Make a reasonably unpredictable id var ts: timespec = undefined; 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 id = @truncate(u32, unsec + unsec / 65536); q[0] = @truncate(u8, id / 256); diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 907fd24db1..899bb2a060 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -706,7 +706,7 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti .restorer = @ptrCast(extern fn () void, restorer_fn), }; 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); const result = syscall4(SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), ksa_mask_size); 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 { - 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: // 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 diff --git a/lib/std/os/uefi.zig b/lib/std/os/uefi.zig index 31d4d2ed50..c780cfd3b5 100644 --- a/lib/std/os/uefi.zig +++ b/lib/std/os/uefi.zig @@ -32,7 +32,7 @@ pub const Guid = extern struct { options: fmt.FormatOptions, context: var, comptime Errors: type, - output: fn (@typeOf(context), []const u8) Errors!void, + output: fn (@TypeOf(context), []const u8) Errors!void, ) Errors!void { 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); diff --git a/lib/std/os/windows/kernel32.zig b/lib/std/os/windows/kernel32.zig index 954261bd1b..33e56abce1 100644 --- a/lib/std/os/windows/kernel32.zig +++ b/lib/std/os/windows/kernel32.zig @@ -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 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( nCount: DWORD, lpHandle: [*]const HANDLE, - bWaitAll:BOOL, + bWaitAll: BOOL, dwMilliseconds: DWORD, bAlertable: BOOL, ) DWORD; diff --git a/lib/std/pdb.zig b/lib/std/pdb.zig index 4b9b3a2a65..db60e60494 100644 --- a/lib/std/pdb.zig +++ b/lib/std/pdb.zig @@ -635,7 +635,7 @@ const MsfStream = struct { /// Implementation of InStream trait for Pdb.MsfStream stream: Stream = undefined, - pub const Error = @typeOf(read).ReturnType.ErrorSet; + pub const Error = @TypeOf(read).ReturnType.ErrorSet; pub const Stream = io.InStream(Error); fn init(block_size: u32, file: File, blocks: []u32) MsfStream { diff --git a/lib/std/reset_event.zig b/lib/std/reset_event.zig index e408c0d0ac..52235d4327 100644 --- a/lib/std/reset_event.zig +++ b/lib/std/reset_event.zig @@ -27,7 +27,7 @@ pub const ResetEvent = struct { pub fn isSet(self: *ResetEvent) bool { return self.os_event.isSet(); } - + /// Sets the event if not already set and /// wakes up AT LEAST one thread waiting the event. /// 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 { - is_set: @typeOf(set_init), + is_set: @TypeOf(set_init), const set_init = if (std.debug.runtime_safety) false else {}; @@ -283,7 +283,7 @@ const PosixEvent = struct { pub fn init() PosixEvent { return PosixEvent{ - .state = .0, + .state = 0, .cond = c.PTHREAD_COND_INITIALIZER, .mutex = c.PTHREAD_MUTEX_INITIALIZER, }; @@ -345,8 +345,8 @@ const PosixEvent = struct { timeout_abs += @intCast(u64, ts.tv_sec) * time.second; timeout_abs += @intCast(u64, ts.tv_nsec); } - 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_sec = @intCast(@TypeOf(ts.tv_sec), @divFloor(timeout_abs, time.second)); + ts.tv_nsec = @intCast(@TypeOf(ts.tv_nsec), @mod(timeout_abs, time.second)); } var dummy_value: u32 = undefined; @@ -426,8 +426,8 @@ test "std.ResetEvent" { .event = event, .value = 0, }; - + var receiver = try std.Thread.spawn(&context, Context.receiver); defer receiver.wait(); try context.sender(); -} \ No newline at end of file +} diff --git a/lib/std/segmented_list.zig b/lib/std/segmented_list.zig index 8c5ded3647..80e4666b6a 100644 --- a/lib/std/segmented_list.zig +++ b/lib/std/segmented_list.zig @@ -122,7 +122,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type 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); return self.uncheckedAt(i); } @@ -213,7 +213,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type 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) { return &self.prealloc_segment[index]; } diff --git a/lib/std/special/build_runner.zig b/lib/std/special/build_runner.zig index 03d1e8fe1d..0a5e435a54 100644 --- a/lib/std/special/build_runner.zig +++ b/lib/std/special/build_runner.zig @@ -125,7 +125,7 @@ pub fn main() !void { } fn runBuild(builder: *Builder) anyerror!void { - switch (@typeId(@typeOf(root.build).ReturnType)) { + switch (@typeId(@TypeOf(root.build).ReturnType)) { .Void => root.build(builder), .ErrorUnion => try root.build(builder), else => @compileError("expected return type of build to be 'void' or '!void'"), diff --git a/lib/std/special/compiler_rt.zig b/lib/std/special/compiler_rt.zig index 1fbb618b1e..0426f72417 100644 --- a/lib/std/special/compiler_rt.zig +++ b/lib/std/special/compiler_rt.zig @@ -384,7 +384,7 @@ extern fn __aeabi_uidivmod(n: u32, d: u32) extern struct { } { @setRuntimeSafety(is_test); - var result: @typeOf(__aeabi_uidivmod).ReturnType = undefined; + var result: @TypeOf(__aeabi_uidivmod).ReturnType = undefined; result.q = __udivmodsi4(n, d, &result.r); return result; } @@ -395,7 +395,7 @@ extern fn __aeabi_uldivmod(n: u64, d: u64) extern struct { } { @setRuntimeSafety(is_test); - var result: @typeOf(__aeabi_uldivmod).ReturnType = undefined; + var result: @TypeOf(__aeabi_uldivmod).ReturnType = undefined; result.q = __udivmoddi4(n, d, &result.r); return result; } @@ -406,7 +406,7 @@ extern fn __aeabi_idivmod(n: i32, d: i32) extern struct { } { @setRuntimeSafety(is_test); - var result: @typeOf(__aeabi_idivmod).ReturnType = undefined; + var result: @TypeOf(__aeabi_idivmod).ReturnType = undefined; result.q = __divmodsi4(n, d, &result.r); return result; } @@ -417,7 +417,7 @@ extern fn __aeabi_ldivmod(n: i64, d: i64) extern struct { } { @setRuntimeSafety(is_test); - var result: @typeOf(__aeabi_ldivmod).ReturnType = undefined; + var result: @TypeOf(__aeabi_ldivmod).ReturnType = undefined; result.q = __divmoddi4(n, d, &result.r); return result; } diff --git a/lib/std/special/start.zig b/lib/std/special/start.zig index b5e4e2edab..60745dab7f 100644 --- a/lib/std/special/start.zig +++ b/lib/std/special/start.zig @@ -25,7 +25,7 @@ comptime { } } else if (builtin.output_mode == .Exe or @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); } } 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.system_table = system_table; - switch (@typeInfo(@typeOf(root.main).ReturnType)) { + switch (@typeInfo(@TypeOf(root.main).ReturnType)) { .NoReturn => { 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 // there is an event loop. fn callMain() u8 { - switch (@typeInfo(@typeOf(root.main).ReturnType)) { + switch (@typeInfo(@TypeOf(root.main).ReturnType)) { .NoReturn => { root.main(); }, @@ -270,7 +270,7 @@ fn callMain() u8 { } return 1; }; - switch (@typeInfo(@typeOf(result))) { + switch (@typeInfo(@TypeOf(result))) { .Void => return 0, .Int => |info| { if (info.bits != 8) { diff --git a/lib/std/testing.zig b/lib/std/testing.zig index 0aeb2d8eda..437c12ee8b 100644 --- a/lib/std/testing.zig +++ b/lib/std/testing.zig @@ -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, /// then aborts. /// The types must match exactly. -pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { - switch (@typeInfo(@typeOf(actual))) { +pub fn expectEqual(expected: var, actual: @TypeOf(expected)) void { + switch (@typeInfo(@TypeOf(actual))) { .NoReturn, .BoundFn, .Opaque, .Frame, .AnyFrame, - => @compileError("value of type " ++ @typeName(@typeOf(actual)) ++ " encountered"), + => @compileError("value of type " ++ @typeName(@TypeOf(actual)) ++ " encountered"), .Undefined, .Null, @@ -87,7 +87,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { @compileError("Unable to compare untagged union values"); } - const TagType = @TagType(@typeOf(expected)); + const TagType = @TagType(@TypeOf(expected)); const expectedTag = @as(TagType, expected); const actualTag = @as(TagType, actual); @@ -95,7 +95,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { expectEqual(expectedTag, actualTag); // 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))) { expectEqual(@field(expected, fld.name), @field(actual, fld.name)); return; diff --git a/lib/std/thread.zig b/lib/std/thread.zig index d443796df4..dcc762f30e 100644 --- a/lib/std/thread.zig +++ b/lib/std/thread.zig @@ -138,7 +138,7 @@ pub const Thread = struct { }; /// caller must call wait on the returned thread - /// fn startFn(@typeOf(context)) T + /// fn startFn(@TypeOf(context)) T /// where T is u8, noreturn, void, or !void /// caller must call wait on the returned thread pub fn spawn(context: var, comptime startFn: var) SpawnError!*Thread { @@ -147,8 +147,8 @@ pub const Thread = struct { // https://github.com/ziglang/zig/issues/157 const default_stack_size = 16 * 1024 * 1024; - const Context = @typeOf(context); - comptime assert(@ArgType(@typeOf(startFn), 0) == Context); + const Context = @TypeOf(context); + comptime assert(@ArgType(@TypeOf(startFn), 0) == Context); if (builtin.os == builtin.Os.windows) { const WinThread = struct { @@ -158,7 +158,7 @@ pub const Thread = struct { }; extern fn threadMain(raw_arg: windows.LPVOID) windows.DWORD { 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 => { return startFn(arg); }, @@ -201,7 +201,7 @@ pub const Thread = struct { extern fn linuxThreadMain(ctx_addr: usize) u8 { const arg = if (@sizeOf(Context) == 0) {} else @intToPtr(*const Context, ctx_addr).*; - switch (@typeId(@typeOf(startFn).ReturnType)) { + switch (@typeId(@TypeOf(startFn).ReturnType)) { .Int => { return startFn(arg); }, diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index a47e2bdc7e..ba022eec95 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -1,3 +1,14 @@ +// TODO: Remove condition after deprecating 'typeOf'. See https://github.com/ziglang/zig/issues/1348 +test "zig fmt: change @typeOf to @TypeOf" { + try testTransform( + \\const a = @typeOf(@as(usize, 10)); + \\ + , + \\const a = @TypeOf(@as(usize, 10)); + \\ + ); +} + test "zig fmt: comptime struct field" { try testCanonical( \\const Foo = struct { @@ -1060,7 +1071,7 @@ test "zig fmt: line comment after doc comment" { test "zig fmt: float literal with exponent" { try testCanonical( \\test "bit field alignment" { - \\ assert(@typeOf(&blah.b) == *align(1:3:6) const u3); + \\ assert(@TypeOf(&blah.b) == *align(1:3:6) const u3); \\} \\ ); @@ -2593,7 +2604,7 @@ test "zig fmt: comments at several places in struct init" { try testTransform( \\var bar = Bar{ \\ .x = 10, // test - \\ .y = "test" + \\ .y = "test" \\ // test \\}; \\ diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index 09482b5109..9add521c00 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -13,19 +13,19 @@ pub const Error = error{ }; /// Returns whether anything changed -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); +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); var anything_changed: bool = false; // make a passthrough stream that checks whether something changed const MyStream = struct { const MyStream = @This(); - const StreamError = @typeOf(stream).Child.Error; + const StreamError = @TypeOf(stream).Child.Error; const Stream = std.io.OutStream(StreamError); anything_changed_ptr: *bool, - child_stream: @typeOf(stream), + child_stream: @TypeOf(stream), stream: Stream, source_index: usize, source: []const u8, @@ -70,7 +70,7 @@ fn renderRoot( allocator: *mem.Allocator, stream: var, tree: *ast.Tree, -) (@typeOf(stream).Child.Error || Error)!void { +) (@TypeOf(stream).Child.Error || Error)!void { var tok_it = tree.tokens.iterator(0); // 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(); var prev_token = first_token; 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) { .FnProto => { const fn_proto = @fieldParentPtr(ast.Node.FnProto, "base", decl); @@ -325,7 +325,7 @@ fn renderExpression( start_col: *usize, base: *ast.Node, space: Space, -) (@typeOf(stream).Child.Error || Error)!void { +) (@TypeOf(stream).Child.Error || Error)!void { switch (base.id) { .Identifier => { const identifier = @fieldParentPtr(ast.Node.Identifier, "base", base); @@ -1249,7 +1249,13 @@ fn renderExpression( .BuiltinCall => { const builtin_call = @fieldParentPtr(ast.Node.BuiltinCall, "base", base); - try renderToken(tree, stream, builtin_call.builtin_token, indent, start_col, Space.None); // @name + // TODO: Remove condition after deprecating 'typeOf'. See https://github.com/ziglang/zig/issues/1348 + if (mem.eql(u8, tree.tokenSlicePtr(tree.tokens.at(builtin_call.builtin_token)), "@typeOf")) { + try stream.write("@TypeOf"); + } else { + try renderToken(tree, stream, builtin_call.builtin_token, indent, start_col, Space.None); // @name + } + try renderToken(tree, stream, tree.nextToken(builtin_call.builtin_token), indent, start_col, Space.None); // ( var it = builtin_call.params.iterator(0); @@ -1897,7 +1903,7 @@ fn renderVarDecl( indent: usize, start_col: *usize, var_decl: *ast.Node.VarDecl, -) (@typeOf(stream).Child.Error || Error)!void { +) (@TypeOf(stream).Child.Error || Error)!void { if (var_decl.visib_token) |visib_token| { try renderToken(tree, stream, visib_token, indent, start_col, Space.Space); // pub } @@ -1970,7 +1976,7 @@ fn renderParamDecl( start_col: *usize, base: *ast.Node, space: Space, -) (@typeOf(stream).Child.Error || Error)!void { +) (@TypeOf(stream).Child.Error || Error)!void { const param_decl = @fieldParentPtr(ast.Node.ParamDecl, "base", base); try renderDocComments(tree, stream, param_decl, indent, start_col); @@ -1999,7 +2005,7 @@ fn renderStatement( indent: usize, start_col: *usize, base: *ast.Node, -) (@typeOf(stream).Child.Error || Error)!void { +) (@TypeOf(stream).Child.Error || Error)!void { switch (base.id) { .VarDecl => { const var_decl = @fieldParentPtr(ast.Node.VarDecl, "base", base); @@ -2038,7 +2044,7 @@ fn renderTokenOffset( start_col: *usize, space: Space, token_skip_bytes: usize, -) (@typeOf(stream).Child.Error || Error)!void { +) (@TypeOf(stream).Child.Error || Error)!void { if (space == Space.BlockStart) { if (start_col.* < indent + indent_delta) return renderToken(tree, stream, token_index, indent, start_col, Space.Space); @@ -2226,7 +2232,7 @@ fn renderToken( indent: usize, start_col: *usize, 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); } @@ -2236,7 +2242,7 @@ fn renderDocComments( node: var, indent: usize, start_col: *usize, -) (@typeOf(stream).Child.Error || Error)!void { +) (@TypeOf(stream).Child.Error || Error)!void { const comment = node.doc_comments orelse return; var it = comment.lines.iterator(0); const first_token = node.firstToken(); @@ -2302,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) { '\t' => try stream.write(" "), '\r' => {}, diff --git a/src-self-hosted/dep_tokenizer.zig b/src-self-hosted/dep_tokenizer.zig index b4e46bc1ad..eb3500cad1 100644 --- a/src-self-hosted/dep_tokenizer.zig +++ b/src-self-hosted/dep_tokenizer.zig @@ -1021,8 +1021,8 @@ comptime { // output: must be a function that takes a `self` idiom parameter // and a bytes parameter // context: must be that self -fn makeOutput(output: var, context: var) Output(@typeOf(output)) { - return Output(@typeOf(output)){ +fn makeOutput(output: var, context: var) Output(@TypeOf(output)) { + return Output(@TypeOf(output)){ .output = output, .context = context, }; diff --git a/src-self-hosted/ir.zig b/src-self-hosted/ir.zig index 741dbb6e3d..a8f4980fa8 100644 --- a/src-self-hosted/ir.zig +++ b/src-self-hosted/ir.zig @@ -1807,7 +1807,7 @@ pub const Builder = struct { // Look at the params and ref() other instructions comptime var i = 0; 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) { *Inst => @field(inst.params, @memberName(I.Params, i)).ref(self), *BasicBlock => @field(inst.params, @memberName(I.Params, i)).ref(self), diff --git a/src-self-hosted/libc_installation.zig b/src-self-hosted/libc_installation.zig index a8fcc920d5..701823c4be 100644 --- a/src-self-hosted/libc_installation.zig +++ b/src-self-hosted/libc_installation.zig @@ -72,7 +72,7 @@ pub const LibCInstallation = struct { inline for (keys) |key, i| { if (std.mem.eql(u8, name, key)) { found_keys[i].found = true; - switch (@typeInfo(@typeOf(@field(self, key)))) { + switch (@typeInfo(@TypeOf(@field(self, key)))) { .Optional => { if (value.len == 0) { @field(self, key) = null; diff --git a/src-self-hosted/stage1.zig b/src-self-hosted/stage1.zig index 909572bee0..59719a0c7d 100644 --- a/src-self-hosted/stage1.zig +++ b/src-self-hosted/stage1.zig @@ -270,11 +270,9 @@ const FmtError = error{ FileBusy, } || fs.File.OpenError; -fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void { - const file_path = try std.mem.dupe(fmt.allocator, u8, file_path_ref); - defer fmt.allocator.free(file_path); - - if (try fmt.seen.put(file_path, {})) |_| return; +fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void { + if (fmt.seen.exists(file_path)) return; + try fmt.seen.put(file_path); const source_code = io.readFileAlloc(fmt.allocator, file_path) catch |err| switch (err) { error.IsDir, error.AccessDenied => { @@ -341,7 +339,7 @@ const Fmt = struct { color: errmsg.Color, allocator: *mem.Allocator, - const SeenMap = std.StringHashMap(void); + const SeenMap = std.BufSet; }; fn printErrMsgToFile( diff --git a/src-self-hosted/translate_c.zig b/src-self-hosted/translate_c.zig index 134e0b7672..c0ac3fbd52 100644 --- a/src-self-hosted/translate_c.zig +++ b/src-self-hosted/translate_c.zig @@ -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); defer big.deinit(); 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]; const str = big.toString(c.a(), 10) catch |err| switch (err) { error.OutOfMemory => return error.OutOfMemory, @@ -1416,7 +1416,7 @@ fn revertAndWarn( source_loc: ZigClangSourceLocation, comptime format: []const u8, args: var, -) (@typeOf(err) || error{OutOfMemory}) { +) (@TypeOf(err) || error{OutOfMemory}) { rp.activate(); try emitWarning(rp.c, source_loc, format, args); return err; diff --git a/src-self-hosted/type.zig b/src-self-hosted/type.zig index 84efeea68a..d3f3ba746a 100644 --- a/src-self-hosted/type.zig +++ b/src-self-hosted/type.zig @@ -1038,14 +1038,14 @@ pub const Type = struct { }; fn hashAny(x: var, comptime seed: u64) u32 { - switch (@typeInfo(@typeOf(x))) { + switch (@typeInfo(@TypeOf(x))) { .Int => |info| { comptime var rng = comptime std.rand.DefaultPrng.init(seed); const unsigned_x = @bitCast(@IntType(false, info.bits), x); if (info.bits <= 32) { return @as(u32, unsigned_x) *% comptime rng.random.scalar(u32); } 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| { @@ -1069,6 +1069,6 @@ fn hashAny(x: var, comptime seed: u64) u32 { return hashAny(@as(u32, 1), seed); } }, - else => @compileError("implement hash function for " ++ @typeName(@typeOf(x))), + else => @compileError("implement hash function for " ++ @typeName(@TypeOf(x))), } } diff --git a/src/all_types.hpp b/src/all_types.hpp index e364b3d362..747655987c 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -2393,7 +2393,7 @@ struct ScopeFnDef { ZigFn *fn_entry; }; -// This scope is created for a @typeOf. +// This scope is created for a @TypeOf. // All runtime side-effects are elided within it. // NodeTypeFnCallExpr struct ScopeTypeOf { diff --git a/src/analyze.cpp b/src/analyze.cpp index 64a0f14372..f46c4fc07c 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -121,7 +121,7 @@ static ScopeExpr *find_expr_scope(Scope *scope) { } static void update_progress_display(CodeGen *g) { - stage2_progress_update_node(g->sub_progress_node, + stage2_progress_update_node(g->sub_progress_node, g->resolve_queue_index + g->fn_defs_index, g->resolve_queue.length + g->fn_defs.length); } @@ -1732,7 +1732,7 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) { ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry) { ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); buf_resize(&err_set_type->name, 0); - buf_appendf(&err_set_type->name, "@typeOf(%s).ReturnType.ErrorSet", buf_ptr(&fn_entry->symbol_name)); + buf_appendf(&err_set_type->name, "@TypeOf(%s).ReturnType.ErrorSet", buf_ptr(&fn_entry->symbol_name)); err_set_type->data.error_set.err_count = 0; err_set_type->data.error_set.errors = nullptr; err_set_type->data.error_set.infer_fn = fn_entry; diff --git a/src/codegen.cpp b/src/codegen.cpp index a7bf7a50c4..5b0899544d 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -1647,7 +1647,7 @@ static void gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type, ptr_type->data.pointer.vector_index, false); LLVMValueRef loaded_vector = gen_load(g, ptr, ptr_type, ""); LLVMValueRef new_vector = LLVMBuildInsertElement(g->builder, loaded_vector, value, - index_val, ""); + index_val, ""); gen_store(g, new_vector, ptr, ptr_type); return; } @@ -8067,7 +8067,7 @@ static void define_builtin_fns(CodeGen *g) { create_builtin_fn(g, BuiltinFnIdTypeInfo, "typeInfo", 1); create_builtin_fn(g, BuiltinFnIdType, "Type", 1); create_builtin_fn(g, BuiltinFnIdHasField, "hasField", 2); - create_builtin_fn(g, BuiltinFnIdTypeof, "typeOf", 1); // TODO rename to TypeOf + create_builtin_fn(g, BuiltinFnIdTypeof, "TypeOf", 1); create_builtin_fn(g, BuiltinFnIdAddWithOverflow, "addWithOverflow", 4); create_builtin_fn(g, BuiltinFnIdSubWithOverflow, "subWithOverflow", 4); create_builtin_fn(g, BuiltinFnIdMulWithOverflow, "mulWithOverflow", 4); @@ -8407,7 +8407,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) { break; } buf_appendf(contents, "pub const output_mode = OutputMode.%s;\n", out_type); - const char *link_type = g->is_dynamic ? "Dynamic" : "Static"; + const char *link_type = g->is_dynamic ? "Dynamic" : "Static"; buf_appendf(contents, "pub const link_mode = LinkMode.%s;\n", link_type); buf_appendf(contents, "pub const is_test = %s;\n", bool_to_str(g->is_test_build)); buf_appendf(contents, "pub const single_threaded = %s;\n", bool_to_str(g->is_single_threaded)); diff --git a/src/ir.cpp b/src/ir.cpp index 154b258327..5a15b64549 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -9267,7 +9267,7 @@ static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) { } } if (get_scope_typeof(instruction->scope) != nullptr) { - // doesn't count, it's inside a @typeOf() + // doesn't count, it's inside a @TypeOf() continue; } exec_add_error_node(codegen, exec, instruction->source_node, @@ -10413,7 +10413,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted return result; } - bool ok_cv_qualifiers = + bool ok_cv_qualifiers = (!actual_ptr_type->data.pointer.is_const || wanted_ptr_type->data.pointer.is_const) && (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile); if (!ok_cv_qualifiers) { @@ -13779,7 +13779,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst (wanted_type->id == ZigTypeIdOptional && wanted_type->data.maybe.child_type->id == ZigTypeIdEnum)) { IrInstruction *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.maybe.child_type); - if (result == ira->codegen->invalid_instruction) + if (result == ira->codegen->invalid_instruction) return result; return ir_analyze_optional_wrap(ira, result, value, wanted_type, nullptr); @@ -13790,9 +13790,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst (wanted_type->id == ZigTypeIdErrorUnion && wanted_type->data.error_union.payload_type->id == ZigTypeIdEnum)) { IrInstruction *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.error_union.payload_type); - if (result == ira->codegen->invalid_instruction) + if (result == ira->codegen->invalid_instruction) return result; - + return ir_analyze_err_wrap_payload(ira, result, value, wanted_type, nullptr); } @@ -19328,7 +19328,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct { size_t offset = ptr_field->data.x_ptr.data.base_array.elem_index; uint64_t new_index = offset + index; - if (ptr_field->data.x_ptr.data.base_array.array_val->data.x_array.special != + if (ptr_field->data.x_ptr.data.base_array.array_val->data.x_array.special != ConstArraySpecialBuf) { ir_assert(new_index < diff --git a/src/ir_print.cpp b/src/ir_print.cpp index d1ea15f016..06dbe0f2b5 100644 --- a/src/ir_print.cpp +++ b/src/ir_print.cpp @@ -873,7 +873,7 @@ static void ir_print_vector_store_elem(IrPrint *irp, IrInstructionVectorStoreEle } static void ir_print_typeof(IrPrint *irp, IrInstructionTypeOf *instruction) { - fprintf(irp->f, "@typeOf("); + fprintf(irp->f, "@TypeOf("); ir_print_other_instruction(irp, instruction->value); fprintf(irp->f, ")"); } diff --git a/src/translate_c.cpp b/src/translate_c.cpp index 3fe5fced07..eb207231f0 100644 --- a/src/translate_c.cpp +++ b/src/translate_c.cpp @@ -4230,7 +4230,7 @@ static AstNode *resolve_typedef_decl(Context *c, const ZigClangTypedefNameDecl * emit_warning(c, ZigClangTypedefNameDecl_getLocation(typedef_decl), "typedef %s - unresolved child type", buf_ptr(type_name)); c->decl_table.put(typedef_decl, nullptr); - // TODO add global var with type_name equal to @compileError("unable to resolve C type") + // TODO add global var with type_name equal to @compileError("unable to resolve C type") return nullptr; } add_global_var(c, type_name, type_node); @@ -4919,9 +4919,9 @@ static AstNode *parse_ctok_primary_expr(Context *c, CTokenize *ctok, size_t *tok *tok_i += 1; - //if (@typeId(@typeOf(x)) == @import("builtin").TypeId.Pointer) + //if (@typeId(@TypeOf(x)) == @import("builtin").TypeId.Pointer) // @ptrCast(dest, x) - //else if (@typeId(@typeOf(x)) == @import("builtin").TypeId.Integer) + //else if (@typeId(@TypeOf(x)) == @import("builtin").TypeId.Integer) // @intToPtr(dest, x) //else // (dest)(x) @@ -4931,7 +4931,7 @@ static AstNode *parse_ctok_primary_expr(Context *c, CTokenize *ctok, size_t *tok AstNode *typeid_type = trans_create_node_field_access_str(c, import_builtin, "TypeId"); AstNode *typeid_pointer = trans_create_node_field_access_str(c, typeid_type, "Pointer"); AstNode *typeid_integer = trans_create_node_field_access_str(c, typeid_type, "Int"); - AstNode *typeof_x = trans_create_node_builtin_fn_call_str(c, "typeOf"); + AstNode *typeof_x = trans_create_node_builtin_fn_call_str(c, "TypeOf"); typeof_x->data.fn_call_expr.params.append(node_to_cast); AstNode *typeid_value = trans_create_node_builtin_fn_call_str(c, "typeId"); typeid_value->data.fn_call_expr.params.append(typeof_x); diff --git a/test/compare_output.zig b/test/compare_output.zig index 80bac9b1f7..b13c6cf530 100644 --- a/test/compare_output.zig +++ b/test/compare_output.zig @@ -258,12 +258,12 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { cases.add("order-independent declarations", \\const io = @import("std").io; \\const z = io.stdin_fileno; - \\const x : @typeOf(y) = 1234; + \\const x : @TypeOf(y) = 1234; \\const y : u16 = 5678; \\pub fn main() void { \\ 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; \\ stdout.print("OK\n", .{}) catch unreachable; \\ return 0; diff --git a/test/compile_errors.zig b/test/compile_errors.zig index b89287949b..12e9184c57 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -154,7 +154,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ }; \\} , &[_][]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", @@ -854,7 +854,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add("field access of slices", \\export fn entry() void { \\ var slice: []i32 = undefined; - \\ const info = @typeOf(slice).unknown; + \\ const info = @TypeOf(slice).unknown; \\} , &[_][]const u8{ "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", \\export fn entry() usize { - \\ return @sizeOf(@typeOf(null)); + \\ return @sizeOf(@TypeOf(null)); \\} , &[_][]const u8{ "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", \\const x = @import("builtin").bogus; - \\export fn entry() usize { return @sizeOf(@typeOf(x)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } , &[_][]const u8{ "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; \\ \\export fn entry() usize { - \\ return @sizeOf(@typeOf(foo.x)); + \\ return @sizeOf(@TypeOf(foo.x)); \\} , &[_][]const u8{ "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", - \\const a : @typeOf(b) = 0; - \\const b : @typeOf(a) = 0; + \\const a : @TypeOf(b) = 0; + \\const b : @TypeOf(a) = 0; \\export fn entry() void { \\ const c = a + b; \\} @@ -1620,7 +1620,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\var x: f64 = 1.0; \\var y: f32 = x; \\ - \\export fn entry() usize { return @sizeOf(@typeOf(y)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(y)); } , &[_][]const u8{ "tmp.zig:2:14: error: expected type 'f32', found 'f64'", }); @@ -2494,7 +2494,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ } \\} , &[_][]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", }); @@ -2626,7 +2626,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ try foo(); \\} , &[_][]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", @@ -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{ "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{ "tmp.zig:13:15: error: duplicate switch value", "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{ "tmp.zig:13:15: error: duplicate switch value", "tmp.zig:10:15: note: other value is here", @@ -3628,7 +3628,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ 0 => {}, \\ } \\} - \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } , &[_][]const u8{ "tmp.zig:2:5: error: switch must handle all possibilities", }); @@ -3642,7 +3642,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ 206 ... 255 => 3, \\ }; \\} - \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } , &[_][]const u8{ "tmp.zig:6:9: error: duplicate switch value", "tmp.zig:5:14: note: previous value is here", @@ -3655,7 +3655,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ } \\} \\const y: u8 = 100; - \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } , &[_][]const 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 a = derp ++ "foo"; \\ - \\export fn entry() usize { return @sizeOf(@typeOf(a)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(a)); } , &[_][]const u8{ "tmp.zig:3:11: error: expected array, found 'usize'", }); @@ -3683,14 +3683,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return s ++ "foo"; \\} \\var s: [10]u8 = undefined; - \\export fn entry() usize { return @sizeOf(@typeOf(f)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } , &[_][]const u8{ "tmp.zig:2:12: error: unable to evaluate constant expression", }); cases.add("@cImport with bogus include", \\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{ "tmp.zig:1:11: error: C import failed", ".h:1:10: note: 'bogus.h' file not found", @@ -3700,14 +3700,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\const x = 3; \\const y = &x; \\fn foo() *const i32 { return y; } - \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } , &[_][]const u8{ "tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'", }); cases.add("integer overflow error", \\const x : u8 = 300; - \\export fn entry() usize { return @sizeOf(@typeOf(x)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } , &[_][]const 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 { \\ Foo.member_a, \\ Foo.member_b, @@ -3746,21 +3746,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ const result = members[index](); \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(f)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } , &[_][]const u8{ "tmp.zig:20:34: error: expected 1 arguments, found 0", }); cases.add("missing function name", \\fn () void {} - \\export fn entry() usize { return @sizeOf(@typeOf(f)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } , &[_][]const u8{ "tmp.zig:1:1: error: missing function name", }); cases.add("missing param name", \\fn f(i32) void {} - \\export fn entry() usize { return @sizeOf(@typeOf(f)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } , &[_][]const u8{ "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 b() i32 {return 1;} \\fn c() i32 {return 2;} - \\export fn entry() usize { return @sizeOf(@typeOf(fns)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(fns)); } , &[_][]const u8{ "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;} \\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{ "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", \\fn func() bogus {} \\fn func() bogus {} - \\export fn entry() usize { return @sizeOf(@typeOf(func)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(func)); } , &[_][]const u8{ "tmp.zig:2:1: error: redefinition of 'func'", }); @@ -3801,7 +3801,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\var global_var: usize = 1; \\fn get() usize { return global_var; } \\ - \\export fn entry() usize { return @sizeOf(@typeOf(Foo)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(Foo)); } , &[_][]const u8{ "tmp.zig:5:25: error: unable to evaluate constant expression", "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}; \\ - \\export fn entry() usize { return @sizeOf(@typeOf(x)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } , &[_][]const u8{ "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 float_x = @as(f32, 1.0) / @as(f32, 0.0); \\ - \\export fn entry1() usize { return @sizeOf(@typeOf(lit_int_x)); } - \\export fn entry2() usize { return @sizeOf(@typeOf(lit_float_x)); } - \\export fn entry3() usize { return @sizeOf(@typeOf(int_x)); } - \\export fn entry4() usize { return @sizeOf(@typeOf(float_x)); } + \\export fn entry1() usize { return @sizeOf(@TypeOf(lit_int_x)); } + \\export fn entry2() usize { return @sizeOf(@TypeOf(lit_float_x)); } + \\export fn entry3() usize { return @sizeOf(@TypeOf(int_x)); } + \\export fn entry4() usize { return @sizeOf(@TypeOf(float_x)); } , &[_][]const u8{ "tmp.zig:1:21: 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 \\b"; \\ - \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } , &[_][]const u8{ "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 {} \\const invalid = foo > foo; \\ - \\export fn entry() usize { return @sizeOf(@typeOf(invalid)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(invalid)); } , &[_][]const u8{ "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); \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(test1)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(test1)); } , &[_][]const u8{ "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", \\const a: *u8 = null; \\ - \\export fn entry() usize { return @sizeOf(@typeOf(a)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(a)); } , &[_][]const u8{ "tmp.zig:1:16: error: expected type '*u8', found '(null)'", }); @@ -3887,7 +3887,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return 1 / x; \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(y)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(y)); } , &[_][]const u8{ "tmp.zig:3:14: error: division by zero", "tmp.zig:1:14: note: referenced here", @@ -3896,7 +3896,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add("branch on undefined value", \\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{ "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); \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(seventh_fib_number)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(seventh_fib_number)); } , &[_][]const u8{ "tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches", "tmp.zig:1:37: note: referenced here", @@ -4286,7 +4286,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add("@embedFile with bogus file", \\const resource = @embedFile("bogus.txt",); \\ - \\export fn entry() usize { return @sizeOf(@typeOf(resource)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(resource)); } , &[_][]const u8{ "tmp.zig:1:29: error: unable to find '", "bogus.txt'", @@ -4299,7 +4299,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\const a = Foo {.x = get_it()}; \\extern fn get_it() i32; \\ - \\export fn entry() usize { return @sizeOf(@typeOf(a)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(a)); } , &[_][]const u8{ "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; \\ - \\export fn entry() usize { return @sizeOf(@typeOf(a)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(a)); } , &[_][]const u8{ "tmp.zig:6:26: error: unable to evaluate constant expression", "tmp.zig:4:17: note: referenced here", @@ -4344,8 +4344,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return a.* == b.*; \\} \\ - \\export fn entry1() usize { return @sizeOf(@typeOf(bad_eql_1)); } - \\export fn entry2() usize { return @sizeOf(@typeOf(bad_eql_2)); } + \\export fn entry1() usize { return @sizeOf(@TypeOf(bad_eql_1)); } + \\export fn entry2() usize { return @sizeOf(@TypeOf(bad_eql_2)); } , &[_][]const u8{ "tmp.zig:2:14: error: operator not allowed for type '[]u8'", "tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'", @@ -4392,7 +4392,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return -x; \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(y)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(y)); } , &[_][]const u8{ "tmp.zig:3:12: error: negation caused overflow", "tmp.zig:1:14: note: referenced here", @@ -4404,7 +4404,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return a + b; \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(y)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(y)); } , &[_][]const u8{ "tmp.zig:3:14: error: operation caused overflow", "tmp.zig:1:14: note: referenced here", @@ -4416,7 +4416,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return a - b; \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(y)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(y)); } , &[_][]const u8{ "tmp.zig:3:14: error: operation caused overflow", "tmp.zig:1:14: note: referenced here", @@ -4428,7 +4428,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return a * b; \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(y)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(y)); } , &[_][]const u8{ "tmp.zig:3:14: error: operation caused overflow", "tmp.zig:1:14: note: referenced here", @@ -4440,7 +4440,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return @truncate(i8, x); \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(f)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } , &[_][]const u8{ "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 { \\ return foo(1, 2); \\} - \\export fn entry() usize { return @sizeOf(@typeOf(f)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } , &[_][]const u8{ "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 { \\ m.copy(u8, self[0..], m); \\} - \\export fn entry() usize { return @sizeOf(@typeOf(f)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } , &[_][]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); \\} - \\export fn entry() usize { return @sizeOf(@typeOf(f)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } , &[_][]const u8{ "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} }; \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } , &[_][]const u8{ "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; \\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{ "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 a = zero{1}; \\ - \\export fn entry() usize { return @sizeOf(@typeOf(a)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(a)); } , &[_][]const u8{ "tmp.zig:2:11: error: expected type 'type', found 'i32'", }); @@ -4715,7 +4715,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ return 0; \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(testTrickyDefer)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); } , &[_][]const u8{ "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", \\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{ "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.*; \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } , &[_][]const u8{ "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]; \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(pass)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(pass)); } , &[_][]const 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; \\} \\ - \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } + \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } , &[_][]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", \\comptime { - \\ _ = @ArgType(@typeOf(add), 2); + \\ _ = @ArgType(@TypeOf(add), 2); \\} \\fn add(a: i32, b: i32) i32 { return a + b; } , &[_][]const u8{ @@ -6220,7 +6220,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { cases.add("getting return type of generic function", \\fn generic(a: var) void {} \\comptime { - \\ _ = @typeOf(generic).ReturnType; + \\ _ = @TypeOf(generic).ReturnType; \\} , &[_][]const u8{ "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", \\fn generic(a: var) void {} \\comptime { - \\ _ = @ArgType(@typeOf(generic), 0); + \\ _ = @ArgType(@TypeOf(generic), 0); \\} , &[_][]const u8{ "tmp.zig:3:36: error: @ArgType could not resolve the type of arg 0 because 'fn(var)var' is generic", diff --git a/test/stage1/behavior/align.zig b/test/stage1/behavior/align.zig index 7f9ccaff1e..1812394f2e 100644 --- a/test/stage1/behavior/align.zig +++ b/test/stage1/behavior/align.zig @@ -5,10 +5,10 @@ const builtin = @import("builtin"); var foo: u8 align(4) = 100; test "global variable alignment" { - expect(@typeOf(&foo).alignment == 4); - expect(@typeOf(&foo) == *align(4) u8); + expect(@TypeOf(&foo).alignment == 4); + expect(@TypeOf(&foo) == *align(4) u8); 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 { @@ -19,8 +19,8 @@ fn noop4() align(4) void {} test "function alignment" { expect(derp() == 1234); - expect(@typeOf(noop1) == fn () align(1) void); - expect(@typeOf(noop4) == fn () align(4) void); + expect(@TypeOf(noop1) == fn () align(1) void); + expect(@TypeOf(noop4) == fn () align(4) void); noop1(); noop4(); } @@ -31,7 +31,7 @@ var baz: packed struct { } = undefined; test "packed struct alignment" { - expect(@typeOf(&baz.b) == *align(1) u32); + expect(@TypeOf(&baz.b) == *align(1) u32); } const blah: packed struct { @@ -41,7 +41,7 @@ const blah: packed struct { } = undefined; 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" { @@ -165,28 +165,28 @@ fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 { test "@ptrCast preserves alignment of bigger source" { var x: u32 align(16) = 1234; 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" { // take full advantage of over-alignment var array align(4) = [_]u8{ 1, 2, 3, 4 }; - expect(@typeOf(&array[0]) == *align(4) u8); - expect(@typeOf(&array[1]) == *u8); - expect(@typeOf(&array[2]) == *align(2) u8); - expect(@typeOf(&array[3]) == *u8); + expect(@TypeOf(&array[0]) == *align(4) u8); + expect(@TypeOf(&array[1]) == *u8); + expect(@TypeOf(&array[2]) == *align(2) u8); + expect(@TypeOf(&array[3]) == *u8); // because align is too small but we still figure out to use 2 var bigger align(2) = [_]u64{ 1, 2, 3, 4 }; - expect(@typeOf(&bigger[0]) == *align(2) u64); - expect(@typeOf(&bigger[1]) == *align(2) u64); - expect(@typeOf(&bigger[2]) == *align(2) u64); - expect(@typeOf(&bigger[3]) == *align(2) u64); + expect(@TypeOf(&bigger[0]) == *align(2) u64); + expect(@TypeOf(&bigger[1]) == *align(2) u64); + expect(@TypeOf(&bigger[2]) == *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 var smaller align(2) = [_]u32{ 1, 2, 3, 4 }; - comptime expect(@typeOf(smaller[0..]) == []align(2) u32); - comptime expect(@typeOf(smaller[0..].ptr) == [*]align(2) u32); + comptime expect(@TypeOf(smaller[0..]) == []align(2) u32); + comptime expect(@TypeOf(smaller[0..].ptr) == [*]align(2) u32); testIndex(smaller[0..].ptr, 0, *align(2) u32); testIndex(smaller[0..].ptr, 1, *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); } 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 { - comptime expect(@typeOf(&ptr[index]) == T); + comptime expect(@TypeOf(&ptr[index]) == T); } test "alignstack" { @@ -303,7 +303,7 @@ test "struct field explicit alignment" { var node: S.Node = undefined; 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); } diff --git a/test/stage1/behavior/array.zig b/test/stage1/behavior/array.zig index 1d51f822d0..7ac1e8197d 100644 --- a/test/stage1/behavior/array.zig +++ b/test/stage1/behavior/array.zig @@ -30,7 +30,7 @@ test "void arrays" { var array: [4]void = undefined; array[0] = void{}; array[1] = array[2]; - expect(@sizeOf(@typeOf(array)) == 0); + expect(@sizeOf(@TypeOf(array)) == 0); expect(array.len == 4); } @@ -109,12 +109,12 @@ test "array literal with specified size" { test "array child property" { var x: [5]i32 = undefined; - expect(@typeOf(x).Child == i32); + expect(@TypeOf(x).Child == i32); } test "array len property" { var x: [5]i32 = undefined; - expect(@typeOf(x).len == 5); + expect(@TypeOf(x).len == 5); } test "array len field" { diff --git a/test/stage1/behavior/async_fn.zig b/test/stage1/behavior/async_fn.zig index cbc8f5e9e8..1b21ba7eff 100644 --- a/test/stage1/behavior/async_fn.zig +++ b/test/stage1/behavior/async_fn.zig @@ -185,7 +185,7 @@ var a_promise: anyframe = undefined; var global_result = false; async fn testSuspendBlock() void { suspend { - comptime expect(@typeOf(@frame()) == *@Frame(testSuspendBlock)); + comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock)); a_promise = @frame(); } @@ -282,7 +282,7 @@ test "async fn pointer in a struct field" { var foo = Foo{ .bar = simpleAsyncFn2 }; var bytes: [64]u8 align(16) = undefined; const f = @asyncCall(&bytes, {}, foo.bar, &data); - comptime expect(@typeOf(f) == anyframe->void); + comptime expect(@TypeOf(f) == anyframe->void); expect(data == 2); resume f; expect(data == 4); @@ -332,7 +332,7 @@ test "async fn with inferred error set" { fn doTheTest() void { var frame: [1]@Frame(middle) = undefined; 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); resume global_frame; std.testing.expectError(error.Fail, result); @@ -952,7 +952,7 @@ test "@asyncCall with comptime-known function, but not awaited directly" { fn doTheTest() void { 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); resume global_frame; 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 bytes: [64]u8 align(16) = undefined; const f = @asyncCall(&bytes, {}, foo.bar, &data); - comptime expect(@typeOf(f) == anyframe->i32); + comptime expect(@TypeOf(f) == anyframe->i32); expect(data == 2); resume f; expect(data == 4); @@ -1017,18 +1017,18 @@ test "@asyncCall using the result location inside the frame" { 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 { fn func(comptime x: var) anyerror!i32 { - const T = @typeOf(async func(x)); - comptime expect(T == @typeOf(@frame()).Child); + const T = @TypeOf(async func(x)); + comptime expect(T == @TypeOf(@frame()).Child); return undefined; } }; _ = async S.func(i32); } -test "using @typeOf on a generic function call" { +test "using @TypeOf on a generic function call" { const S = struct { var global_frame: anyframe = undefined; var global_ok = false; @@ -1043,7 +1043,7 @@ test "using @typeOf on a generic function call" { suspend { global_frame = @frame(); } - const F = @typeOf(async amain(x - 1)); + const F = @TypeOf(async amain(x - 1)); const frame = @intToPtr(*F, @ptrToInt(&buf)); return await @asyncCall(frame, {}, amain, x - 1); } @@ -1068,7 +1068,7 @@ test "recursive call of await @asyncCall with struct return type" { suspend { global_frame = @frame(); } - const F = @typeOf(async amain(x - 1)); + const F = @TypeOf(async amain(x - 1)); const frame = @intToPtr(*F, @ptrToInt(&buf)); 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 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)); resume S.global_frame; expect(S.global_ok); diff --git a/test/stage1/behavior/atomics.zig b/test/stage1/behavior/atomics.zig index 694eb160e4..d76be6ce6f 100644 --- a/test/stage1/behavior/atomics.zig +++ b/test/stage1/behavior/atomics.zig @@ -118,7 +118,7 @@ test "atomic load and rmw with enum" { expect(@atomicLoad(Value, &x, .SeqCst) != .b); - _ = @atomicRmw(Value, &x, .Xchg, .c, .SeqCst); + _ = @atomicRmw(Value, &x, .Xchg, .c, .SeqCst); expect(@atomicLoad(Value, &x, .SeqCst) == .c); expect(@atomicLoad(Value, &x, .SeqCst) != .a); expect(@atomicLoad(Value, &x, .SeqCst) != .b); @@ -143,4 +143,4 @@ fn testAtomicStore() void { expect(@atomicLoad(u32, &x, .SeqCst) == 1); @atomicStore(u32, &x, 12345678, .SeqCst); expect(@atomicLoad(u32, &x, .SeqCst) == 12345678); -} \ No newline at end of file +} diff --git a/test/stage1/behavior/bugs/1851.zig b/test/stage1/behavior/bugs/1851.zig index ff9ab419f8..679f4bf835 100644 --- a/test/stage1/behavior/bugs/1851.zig +++ b/test/stage1/behavior/bugs/1851.zig @@ -15,7 +15,7 @@ test "allocation and looping over 3-byte integer" { x[1] = 0xFFFFFF; const bytes = @sliceToBytes(x); - expect(@typeOf(bytes) == []align(4) u8); + expect(@TypeOf(bytes) == []align(4) u8); expect(bytes.len == 8); for (bytes) |*b| { diff --git a/test/stage1/behavior/bugs/2114.zig b/test/stage1/behavior/bugs/2114.zig index 5b664e64ef..ab32a22cf3 100644 --- a/test/stage1/behavior/bugs/2114.zig +++ b/test/stage1/behavior/bugs/2114.zig @@ -3,7 +3,7 @@ const expect = std.testing.expect; const math = std.math; fn ctz(x: var) usize { - return @ctz(@typeOf(x), x); + return @ctz(@TypeOf(x), x); } test "fixed" { diff --git a/test/stage1/behavior/bugs/3742.zig b/test/stage1/behavior/bugs/3742.zig index 74aed006f6..01bcb49f3c 100644 --- a/test/stage1/behavior/bugs/3742.zig +++ b/test/stage1/behavior/bugs/3742.zig @@ -24,7 +24,7 @@ pub fn isCommand(comptime T: type) bool { pub const ArgSerializer = struct { pub fn serializeCommand(command: var) void { - const CmdT = @typeOf(command); + const CmdT = @TypeOf(command); if (comptime isCommand(CmdT)) { // COMMENTING THE NEXT LINE REMOVES THE ERROR diff --git a/test/stage1/behavior/bugs/655.zig b/test/stage1/behavior/bugs/655.zig index d4491bfc27..3d1bccb183 100644 --- a/test/stage1/behavior/bugs/655.zig +++ b/test/stage1/behavior/bugs/655.zig @@ -3,7 +3,7 @@ const other_file = @import("655_other_file.zig"); test "function with *const parameter with type dereferenced by namespace" { const x: other_file.Integer = 1234; - comptime std.testing.expect(@typeOf(&x) == *const other_file.Integer); + comptime std.testing.expect(@TypeOf(&x) == *const other_file.Integer); foo(&x); } diff --git a/test/stage1/behavior/bugs/718.zig b/test/stage1/behavior/bugs/718.zig index 8dfb511bb4..b5a57b8944 100644 --- a/test/stage1/behavior/bugs/718.zig +++ b/test/stage1/behavior/bugs/718.zig @@ -9,7 +9,7 @@ const Keys = struct { }; var keys: Keys = undefined; test "zero keys with @memset" { - @memset(@ptrCast([*]u8, &keys), 0, @sizeOf(@typeOf(keys))); + @memset(@ptrCast([*]u8, &keys), 0, @sizeOf(@TypeOf(keys))); expect(!keys.up); expect(!keys.down); expect(!keys.left); diff --git a/test/stage1/behavior/cast.zig b/test/stage1/behavior/cast.zig index 05749142c6..b5dd99a858 100644 --- a/test/stage1/behavior/cast.zig +++ b/test/stage1/behavior/cast.zig @@ -226,14 +226,14 @@ fn testCastConstArrayRefToConstSlice() void { { const blah = "aoeu".*; const const_array_ref = &blah; - expect(@typeOf(const_array_ref) == *const [4:0]u8); + expect(@TypeOf(const_array_ref) == *const [4:0]u8); const slice: []const u8 = const_array_ref; expect(mem.eql(u8, slice, "aoeu")); } { const blah: [4]u8 = "aoeu".*; const const_array_ref = &blah; - expect(@typeOf(const_array_ref) == *const [4]u8); + expect(@TypeOf(const_array_ref) == *const [4]u8); const slice: []const u8 = const_array_ref; expect(mem.eql(u8, slice, "aoeu")); } @@ -353,29 +353,29 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" { test "@intCast comptime_int" { const result = @intCast(i32, 1234); - expect(@typeOf(result) == i32); + expect(@TypeOf(result) == i32); expect(result == 1234); } test "@floatCast comptime_int and comptime_float" { { const result = @floatCast(f16, 1234); - expect(@typeOf(result) == f16); + expect(@TypeOf(result) == f16); expect(result == 1234.0); } { const result = @floatCast(f16, 1234.0); - expect(@typeOf(result) == f16); + expect(@TypeOf(result) == f16); expect(result == 1234.0); } { const result = @floatCast(f32, 1234); - expect(@typeOf(result) == f32); + expect(@TypeOf(result) == f32); expect(result == 1234.0); } { const result = @floatCast(f32, 1234.0); - expect(@typeOf(result) == f32); + expect(@TypeOf(result) == f32); expect(result == 1234.0); } } @@ -383,12 +383,12 @@ test "@floatCast comptime_int and comptime_float" { test "comptime_int @intToFloat" { { const result = @intToFloat(f16, 1234); - expect(@typeOf(result) == f16); + expect(@TypeOf(result) == f16); expect(result == 1234.0); } { const result = @intToFloat(f32, 1234); - expect(@typeOf(result) == f32); + expect(@TypeOf(result) == f32); expect(result == 1234.0); } } @@ -396,7 +396,7 @@ test "comptime_int @intToFloat" { test "@bytesToSlice keeps pointer alignment" { var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 }; const numbers = @bytesToSlice(u32, bytes[0..]); - comptime expect(@typeOf(numbers) == []align(@alignOf(@typeOf(bytes))) u32); + comptime expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32); } test "@intCast i32 to u7" { diff --git a/test/stage1/behavior/error.zig b/test/stage1/behavior/error.zig index f9b331caaf..7c1e093748 100644 --- a/test/stage1/behavior/error.zig +++ b/test/stage1/behavior/error.zig @@ -83,9 +83,9 @@ test "error union type " { fn testErrorUnionType() void { const x: anyerror!i32 = 1234; if (x) |value| expect(value == 1234) else |_| unreachable; - expect(@typeId(@typeOf(x)) == builtin.TypeId.ErrorUnion); - expect(@typeId(@typeOf(x).ErrorSet) == builtin.TypeId.ErrorSet); - expect(@typeOf(x).ErrorSet == anyerror); + expect(@typeId(@TypeOf(x)) == builtin.TypeId.ErrorUnion); + expect(@typeId(@TypeOf(x).ErrorSet) == builtin.TypeId.ErrorSet); + expect(@TypeOf(x).ErrorSet == anyerror); } test "error set type" { diff --git a/test/stage1/behavior/eval.zig b/test/stage1/behavior/eval.zig index 44ad2f81fa..e33def59c4 100644 --- a/test/stage1/behavior/eval.zig +++ b/test/stage1/behavior/eval.zig @@ -105,7 +105,7 @@ pub fn vec3(x: f32, y: f32, z: f32) Vec3 { test "constant expressions" { var array: [array_size]u8 = undefined; - expect(@sizeOf(@typeOf(array)) == 20); + expect(@sizeOf(@TypeOf(array)) == 20); } const array_size: u8 = 20; @@ -598,7 +598,7 @@ test "pointer to type" { var T: type = i32; expect(T == i32); var ptr = &T; - expect(@typeOf(ptr) == *type); + expect(@TypeOf(ptr) == *type); ptr.* = f32; expect(T == f32); expect(*T == *f32); diff --git a/test/stage1/behavior/fn.zig b/test/stage1/behavior/fn.zig index 385b8bc418..654405df44 100644 --- a/test/stage1/behavior/fn.zig +++ b/test/stage1/behavior/fn.zig @@ -73,7 +73,7 @@ fn fnWithUnreachable() noreturn { } test "function pointers" { - const fns = [_]@typeOf(fn1){ + const fns = [_]@TypeOf(fn1){ fn1, fn2, fn3, @@ -130,7 +130,7 @@ test "pass by non-copying value through var arg" { } fn addPointCoordsVar(pt: var) i32 { - comptime expect(@typeOf(pt) == Point); + comptime expect(@TypeOf(pt) == Point); return pt.x + pt.y; } @@ -170,7 +170,7 @@ test "pass by non-copying value as method, at comptime" { } fn outer(y: u32) fn (u32) u32 { - const Y = @typeOf(y); + const Y = @TypeOf(y); const st = struct { fn get(z: u32) u32 { return z + @sizeOf(Y); @@ -265,7 +265,7 @@ test "ability to give comptime types and non comptime types to same parameter" { } fn foo(arg: var) i32 { - if (@typeInfo(@typeOf(arg)) == .Type and arg == i32) return 20; + if (@typeInfo(@TypeOf(arg)) == .Type and arg == i32) return 20; return 9 + arg; } }; diff --git a/test/stage1/behavior/for.zig b/test/stage1/behavior/for.zig index 5cf75ed497..29b6f934f0 100644 --- a/test/stage1/behavior/for.zig +++ b/test/stage1/behavior/for.zig @@ -29,9 +29,9 @@ test "for loop with pointer elem var" { expect(mem.eql(u8, &target, "bcdefgh")); for (source) |*c, i| - expect(@typeOf(c) == *const u8); + expect(@TypeOf(c) == *const u8); for (target) |*c, i| - expect(@typeOf(c) == *u8); + expect(@TypeOf(c) == *u8); } fn mangleString(s: []u8) void { diff --git a/test/stage1/behavior/generics.zig b/test/stage1/behavior/generics.zig index dc15ae1b8c..a5d2f9dabe 100644 --- a/test/stage1/behavior/generics.zig +++ b/test/stage1/behavior/generics.zig @@ -47,7 +47,7 @@ comptime { expect(max_f64(1.2, 3.4) == 3.4); } -fn max_var(a: var, b: var) @typeOf(a + b) { +fn max_var(a: var, b: var) @TypeOf(a + b) { return if (a > b) a else b; } diff --git a/test/stage1/behavior/math.zig b/test/stage1/behavior/math.zig index 37a23fa325..751275aeb6 100644 --- a/test/stage1/behavior/math.zig +++ b/test/stage1/behavior/math.zig @@ -281,8 +281,8 @@ test "small int addition" { x += 1; expect(x == 3); - var result: @typeOf(x) = 3; - expect(@addWithOverflow(@typeOf(x), x, 1, &result)); + var result: @TypeOf(x) = 3; + expect(@addWithOverflow(@TypeOf(x), x, 1, &result)); expect(result == 0); } @@ -586,7 +586,7 @@ test "@sqrt" { const x = 14.0; const y = x * x; - const z = @sqrt(@typeOf(y), y); + const z = @sqrt(@TypeOf(y), y); comptime expect(z == x); } diff --git a/test/stage1/behavior/misc.zig b/test/stage1/behavior/misc.zig index a3da752f0d..dd3ad29878 100644 --- a/test/stage1/behavior/misc.zig +++ b/test/stage1/behavior/misc.zig @@ -362,8 +362,8 @@ test "string concatenation" { const a = "OK" ++ " IT " ++ "WORKED"; const b = "OK IT WORKED"; - comptime expect(@typeOf(a) == *const [12:0]u8); - comptime expect(@typeOf(b) == *const [12:0]u8); + comptime expect(@TypeOf(a) == *const [12:0]u8); + comptime expect(@TypeOf(b) == *const [12:0]u8); const len = mem.len(u8, b); const len_with_null = len + 1; @@ -460,19 +460,19 @@ test "@typeId" { expect(@typeId(*f32) == Tid.Pointer); expect(@typeId([2]u8) == Tid.Array); expect(@typeId(AStruct) == Tid.Struct); - expect(@typeId(@typeOf(1)) == Tid.ComptimeInt); - expect(@typeId(@typeOf(1.0)) == Tid.ComptimeFloat); - expect(@typeId(@typeOf(undefined)) == Tid.Undefined); - expect(@typeId(@typeOf(null)) == Tid.Null); + expect(@typeId(@TypeOf(1)) == Tid.ComptimeInt); + expect(@typeId(@TypeOf(1.0)) == Tid.ComptimeFloat); + expect(@typeId(@TypeOf(undefined)) == Tid.Undefined); + expect(@typeId(@TypeOf(null)) == Tid.Null); expect(@typeId(?i32) == Tid.Optional); expect(@typeId(anyerror!i32) == Tid.ErrorUnion); expect(@typeId(anyerror) == Tid.ErrorSet); expect(@typeId(AnEnum) == Tid.Enum); - expect(@typeId(@typeOf(AUnionEnum.One)) == Tid.Enum); + expect(@typeId(@TypeOf(AUnionEnum.One)) == Tid.Enum); expect(@typeId(AUnionEnum) == Tid.Union); expect(@typeId(AUnion) == Tid.Union); expect(@typeId(fn () void) == Tid.Fn); - expect(@typeId(@typeOf(builtin)) == Tid.Type); + expect(@typeId(@TypeOf(builtin)) == Tid.Type); // TODO bound fn // TODO arg tuple // TODO opaque @@ -652,9 +652,9 @@ test "volatile load and store" { test "slice string literal has type []const u8" { comptime { - expect(@typeOf("aoeu"[0..]) == []const u8); + expect(@TypeOf("aoeu"[0..]) == []const u8); const array = [_]i32{ 1, 2, 3, 4 }; - expect(@typeOf(array[0..]) == []const i32); + expect(@TypeOf(array[0..]) == []const i32); } } diff --git a/test/stage1/behavior/pointers.zig b/test/stage1/behavior/pointers.zig index 58a46b539c..cb69762eda 100644 --- a/test/stage1/behavior/pointers.zig +++ b/test/stage1/behavior/pointers.zig @@ -93,10 +93,10 @@ test "peer type resolution with C pointers" { var x2 = if (t) ptr_many else ptr_c; var x3 = if (t) ptr_c else ptr_one; var x4 = if (t) ptr_c else ptr_many; - expect(@typeOf(x1) == [*c]u8); - expect(@typeOf(x2) == [*c]u8); - expect(@typeOf(x3) == [*c]u8); - expect(@typeOf(x4) == [*c]u8); + expect(@TypeOf(x1) == [*c]u8); + expect(@TypeOf(x2) == [*c]u8); + expect(@TypeOf(x3) == [*c]u8); + expect(@TypeOf(x4) == [*c]u8); } test "implicit casting between C pointer and optional non-C pointer" { @@ -144,11 +144,11 @@ test "allowzero pointer and slice" { expect(opt_ptr != null); expect(@ptrToInt(ptr) == 0); var slice = ptr[0..10]; - expect(@typeOf(slice) == []allowzero i32); + expect(@TypeOf(slice) == []allowzero i32); expect(@ptrToInt(&slice[5]) == 20); - expect(@typeInfo(@typeOf(ptr)).Pointer.is_allowzero); - expect(@typeInfo(@typeOf(slice)).Pointer.is_allowzero); + expect(@typeInfo(@TypeOf(ptr)).Pointer.is_allowzero); + expect(@typeInfo(@TypeOf(slice)).Pointer.is_allowzero); } test "assign null directly to C pointer and test null equality" { @@ -204,7 +204,7 @@ test "assign null directly to C pointer and test null equality" { test "null terminated pointer" { const S = struct { fn doTheTest() void { - var array_with_zero = [_:0]u8{'h', 'e', 'l', 'l', 'o'}; + var array_with_zero = [_:0]u8{ 'h', 'e', 'l', 'l', 'o' }; var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero); var no_zero_ptr: [*]const u8 = zero_ptr; var zero_ptr_again = @ptrCast([*:0]const u8, no_zero_ptr); @@ -218,7 +218,7 @@ test "null terminated pointer" { test "allow any sentinel" { const S = struct { fn doTheTest() void { - var array = [_:std.math.minInt(i32)]i32{1, 2, 3, 4}; + var array = [_:std.math.minInt(i32)]i32{ 1, 2, 3, 4 }; var ptr: [*:std.math.minInt(i32)]i32 = &array; expect(ptr[4] == std.math.minInt(i32)); } @@ -229,10 +229,14 @@ test "allow any sentinel" { test "pointer sentinel with enums" { const S = struct { - const Number = enum{one, two, sentinel}; + const Number = enum { + one, + two, + sentinel, + }; fn doTheTest() void { - var ptr: [*:.sentinel]Number = &[_:.sentinel]Number{.one, .two, .two, .one}; + var ptr: [*:.sentinel]Number = &[_:.sentinel]Number{ .one, .two, .two, .one }; expect(ptr[4] == .sentinel); // TODO this should be comptime expect, see #3731 } }; @@ -243,7 +247,7 @@ test "pointer sentinel with enums" { test "pointer sentinel with optional element" { const S = struct { fn doTheTest() void { - var ptr: [*:null]?i32 = &[_:null]?i32{1, 2, 3, 4}; + var ptr: [*:null]?i32 = &[_:null]?i32{ 1, 2, 3, 4 }; expect(ptr[4] == null); // TODO this should be comptime expect, see #3731 } }; @@ -255,7 +259,7 @@ test "pointer sentinel with +inf" { const S = struct { fn doTheTest() void { const inf = std.math.inf_f32; - var ptr: [*:inf]f32 = &[_:inf]f32{1.1, 2.2, 3.3, 4.4}; + var ptr: [*:inf]f32 = &[_:inf]f32{ 1.1, 2.2, 3.3, 4.4 }; expect(ptr[4] == inf); // TODO this should be comptime expect, see #3731 } }; diff --git a/test/stage1/behavior/ptrcast.zig b/test/stage1/behavior/ptrcast.zig index 4c17b38e6e..1c1cf251a0 100644 --- a/test/stage1/behavior/ptrcast.zig +++ b/test/stage1/behavior/ptrcast.zig @@ -55,7 +55,7 @@ test "comptime ptrcast keeps larger alignment" { comptime { const a: u32 = 1234; const p = @ptrCast([*]const u8, &a); - std.debug.assert(@typeOf(p) == [*]align(@alignOf(u32)) const u8); + std.debug.assert(@TypeOf(p) == [*]align(@alignOf(u32)) const u8); } } diff --git a/test/stage1/behavior/reflection.zig b/test/stage1/behavior/reflection.zig index 12067ee51d..37bf2a582c 100644 --- a/test/stage1/behavior/reflection.zig +++ b/test/stage1/behavior/reflection.zig @@ -13,12 +13,12 @@ test "reflection: array, pointer, optional, error union type child" { test "reflection: function return type, var args, and param types" { comptime { - expect(@typeOf(dummy).ReturnType == i32); - expect(!@typeOf(dummy).is_var_args); - expect(@typeOf(dummy).arg_count == 3); - expect(@ArgType(@typeOf(dummy), 0) == bool); - expect(@ArgType(@typeOf(dummy), 1) == i32); - expect(@ArgType(@typeOf(dummy), 2) == f32); + expect(@TypeOf(dummy).ReturnType == i32); + expect(!@TypeOf(dummy).is_var_args); + expect(@TypeOf(dummy).arg_count == 3); + expect(@ArgType(@TypeOf(dummy), 0) == bool); + expect(@ArgType(@TypeOf(dummy), 1) == i32); + expect(@ArgType(@TypeOf(dummy), 2) == f32); } } diff --git a/test/stage1/behavior/sizeof_and_typeof.zig b/test/stage1/behavior/sizeof_and_typeof.zig index 0369be9989..d46cdccd0d 100644 --- a/test/stage1/behavior/sizeof_and_typeof.zig +++ b/test/stage1/behavior/sizeof_and_typeof.zig @@ -1,12 +1,12 @@ const builtin = @import("builtin"); const expect = @import("std").testing.expect; -test "@sizeOf and @typeOf" { - const y: @typeOf(x) = 120; - expect(@sizeOf(@typeOf(y)) == 2); +test "@sizeOf and @TypeOf" { + const y: @TypeOf(x) = 120; + expect(@sizeOf(@TypeOf(y)) == 2); } const x: u16 = 13; -const z: @typeOf(x) = 19; +const z: @TypeOf(x) = 19; const A = struct { a: u8, @@ -71,8 +71,8 @@ test "@bitOffsetOf" { test "@sizeOf on compile-time types" { expect(@sizeOf(comptime_int) == 0); expect(@sizeOf(comptime_float) == 0); - expect(@sizeOf(@typeOf(.hi)) == 0); - expect(@sizeOf(@typeOf(type)) == 0); + expect(@sizeOf(@TypeOf(.hi)) == 0); + expect(@sizeOf(@TypeOf(type)) == 0); } test "@sizeOf(T) == 0 doesn't force resolving struct size" { @@ -90,7 +90,7 @@ test "@sizeOf(T) == 0 doesn't force resolving struct size" { expect(@sizeOf(S.Bar) == 8); } -test "@typeOf() has no runtime side effects" { +test "@TypeOf() has no runtime side effects" { const S = struct { fn foo(comptime T: type, ptr: *T) T { ptr.* += 1; @@ -98,12 +98,12 @@ test "@typeOf() has no runtime side effects" { } }; var data: i32 = 0; - const T = @typeOf(S.foo(i32, &data)); + const T = @TypeOf(S.foo(i32, &data)); comptime expect(T == i32); expect(data == 0); } -test "branching logic inside @typeOf" { +test "branching logic inside @TypeOf" { const S = struct { var data: i32 = 0; fn foo() anyerror!i32 { @@ -111,7 +111,7 @@ test "branching logic inside @typeOf" { return undefined; } }; - const T = @typeOf(S.foo() catch undefined); + const T = @TypeOf(S.foo() catch undefined); comptime expect(T == i32); expect(S.data == 0); } diff --git a/test/stage1/behavior/switch.zig b/test/stage1/behavior/switch.zig index 1a18a5c440..625585cd9e 100644 --- a/test/stage1/behavior/switch.zig +++ b/test/stage1/behavior/switch.zig @@ -406,7 +406,7 @@ test "switch prongs with cases with identical payload types" { fn doTheSwitch1(u: Union) void { switch (u) { .A, .C => |e| { - expect(@typeOf(e) == usize); + expect(@TypeOf(e) == usize); expect(e == 8); }, .B => |e| @panic("fail"), @@ -416,7 +416,7 @@ test "switch prongs with cases with identical payload types" { switch (u) { .A, .C => |e| @panic("fail"), .B => |e| { - expect(@typeOf(e) == isize); + expect(@TypeOf(e) == isize); expect(e == -8); }, } diff --git a/test/stage1/behavior/type.zig b/test/stage1/behavior/type.zig index dfdc729c42..67c78b305f 100644 --- a/test/stage1/behavior/type.zig +++ b/test/stage1/behavior/type.zig @@ -125,10 +125,10 @@ test "Type.ComptimeInt" { testTypes(&[_]type{comptime_int}); } test "Type.Undefined" { - testTypes(&[_]type{@typeOf(undefined)}); + testTypes(&[_]type{@TypeOf(undefined)}); } test "Type.Null" { - testTypes(&[_]type{@typeOf(null)}); + testTypes(&[_]type{@TypeOf(null)}); } test "@Type create slice with null sentinel" { const Slice = @Type(builtin.TypeInfo{ diff --git a/test/stage1/behavior/type_info.zig b/test/stage1/behavior/type_info.zig index a0fd4a4e6c..5a7268443d 100644 --- a/test/stage1/behavior/type_info.zig +++ b/test/stage1/behavior/type_info.zig @@ -201,7 +201,7 @@ fn testUnion() void { expect(typeinfo_info.Union.fields.len == 25); expect(typeinfo_info.Union.fields[4].enum_field != null); expect(typeinfo_info.Union.fields[4].enum_field.?.value == 4); - expect(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int)); + expect(typeinfo_info.Union.fields[4].field_type == @TypeOf(@typeInfo(u8).Int)); expect(typeinfo_info.Union.decls.len == 21); const TestNoTagUnion = union { @@ -264,7 +264,7 @@ test "type info: function type info" { } fn testFunction() void { - const fn_info = @typeInfo(@typeOf(foo)); + const fn_info = @typeInfo(@TypeOf(foo)); expect(@as(TypeId, fn_info) == TypeId.Fn); expect(fn_info.Fn.calling_convention == TypeInfo.CallingConvention.Unspecified); expect(fn_info.Fn.is_generic); @@ -273,7 +273,7 @@ fn testFunction() void { expect(fn_info.Fn.return_type == null); const test_instance: TestStruct = undefined; - const bound_fn_info = @typeInfo(@typeOf(test_instance.foo)); + const bound_fn_info = @typeInfo(@TypeOf(test_instance.foo)); expect(@as(TypeId, bound_fn_info) == TypeId.BoundFn); expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct); } diff --git a/test/stage1/behavior/undefined.zig b/test/stage1/behavior/undefined.zig index 4f2cbed3bc..3506e7e240 100644 --- a/test/stage1/behavior/undefined.zig +++ b/test/stage1/behavior/undefined.zig @@ -64,5 +64,5 @@ test "assign undefined to struct with method" { test "type name of undefined" { const x = undefined; - expect(mem.eql(u8, @typeName(@typeOf(x)), "(undefined)")); + expect(mem.eql(u8, @typeName(@TypeOf(x)), "(undefined)")); } diff --git a/test/stage1/behavior/vector.zig b/test/stage1/behavior/vector.zig index b6033ea660..338f24d806 100644 --- a/test/stage1/behavior/vector.zig +++ b/test/stage1/behavior/vector.zig @@ -148,7 +148,7 @@ test "vector @splat" { fn doTheTest() void { var v: u32 = 5; var x = @splat(4, v); - expect(@typeOf(x) == @Vector(4, u32)); + expect(@TypeOf(x) == @Vector(4, u32)); var array_x: [4]u32 = x; expect(array_x[0] == 5); expect(array_x[1] == 5); diff --git a/test/translate_c.zig b/test/translate_c.zig index a2ee07f219..aa27651241 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -1539,7 +1539,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { cases.add("macro pointer cast", \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE) , &[_][]const u8{ - \\pub const NRF_GPIO = if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Pointer) @ptrCast([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Int) @intToPtr([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else @as([*c]NRF_GPIO_Type, NRF_GPIO_BASE); + \\pub const NRF_GPIO = if (@typeId(@TypeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Pointer) @ptrCast([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else if (@typeId(@TypeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Int) @intToPtr([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else @as([*c]NRF_GPIO_Type, NRF_GPIO_BASE); }); cases.add("if on non-bool", diff --git a/tools/merge_anal_dumps.zig b/tools/merge_anal_dumps.zig index c62b8aa848..e0e71696d6 100644 --- a/tools/merge_anal_dumps.zig +++ b/tools/merge_anal_dumps.zig @@ -311,7 +311,7 @@ const Dump = struct { } fn render(self: *Dump, stream: var) !void { - var jw = json.WriteStream(@typeOf(stream).Child, 10).init(stream); + var jw = json.WriteStream(@TypeOf(stream).Child, 10).init(stream); try jw.beginObject(); try jw.objectField("typeKinds");