authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-10 11:13:39-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-10 11:13:39-05:00
log9561e7c6b9fb2d9ebcbfd611196db698372ae7bd
tree6b4fd0751e80a9c4128756d59d3c0bfecd230498
parentcd4d638d10365e47bcb371119dcee22581355ac4
parent30715560c829d5636734edf7eabff3ee4d170e5d
signature Commit is signed but in an unrecognized format.

Merge branch 'Snektron-typeOf-to-TypeOf'

closes #3875 closes #1348

134 files changed, 604 insertions(+), 585 deletions(-)

doc/langref.html.in+52-52
...@@ -307,7 +307,7 @@ pub fn main() void {...@@ -307,7 +307,7 @@ pub fn main() void {
307 assert(optional_value == null);307 assert(optional_value == null);
308308
309 warn("\noptional 1\ntype: {}\nvalue: {}\n", .{309 warn("\noptional 1\ntype: {}\nvalue: {}\n", .{
310 @typeName(@typeOf(optional_value)),310 @typeName(@TypeOf(optional_value)),
311 optional_value,311 optional_value,
312 });312 });
313313
...@@ -315,7 +315,7 @@ pub fn main() void {...@@ -315,7 +315,7 @@ pub fn main() void {
315 assert(optional_value != null);315 assert(optional_value != null);
316316
317 warn("\noptional 2\ntype: {}\nvalue: {}\n", .{317 warn("\noptional 2\ntype: {}\nvalue: {}\n", .{
318 @typeName(@typeOf(optional_value)),318 @typeName(@TypeOf(optional_value)),
319 optional_value,319 optional_value,
320 });320 });
321321
...@@ -323,14 +323,14 @@ pub fn main() void {...@@ -323,14 +323,14 @@ pub fn main() void {
323 var number_or_error: anyerror!i32 = error.ArgNotFound;323 var number_or_error: anyerror!i32 = error.ArgNotFound;
324324
325 warn("\nerror union 1\ntype: {}\nvalue: {}\n", .{325 warn("\nerror union 1\ntype: {}\nvalue: {}\n", .{
326 @typeName(@typeOf(number_or_error)),326 @typeName(@TypeOf(number_or_error)),
327 number_or_error,327 number_or_error,
328 });328 });
329329
330 number_or_error = 1234;330 number_or_error = 1234;
331331
332 warn("\nerror union 2\ntype: {}\nvalue: {}\n", .{332 warn("\nerror union 2\ntype: {}\nvalue: {}\n", .{
333 @typeName(@typeOf(number_or_error)),333 @typeName(@TypeOf(number_or_error)),
334 number_or_error,334 number_or_error,
335 });335 });
336}336}
...@@ -572,7 +572,7 @@ const mem = @import("std").mem;...@@ -572,7 +572,7 @@ const mem = @import("std").mem;
572572
573test "string literals" {573test "string literals" {
574 const bytes = "hello";574 const bytes = "hello";
575 assert(@typeOf(bytes) == *const [5:0]u8);575 assert(@TypeOf(bytes) == *const [5:0]u8);
576 assert(bytes.len == 5);576 assert(bytes.len == 5);
577 assert(bytes[1] == 'e');577 assert(bytes[1] == 'e');
578 assert(bytes[5] == 0);578 assert(bytes[5] == 0);
...@@ -1802,7 +1802,7 @@ const assert = std.debug.assert;...@@ -1802,7 +1802,7 @@ const assert = std.debug.assert;
1802test "null terminated array" {1802test "null terminated array" {
1803 const array = [_:0]u8 {1, 2, 3, 4};1803 const array = [_:0]u8 {1, 2, 3, 4};
18041804
1805 assert(@typeOf(array) == [4:0]u8);1805 assert(@TypeOf(array) == [4:0]u8);
1806 assert(array.len == 4);1806 assert(array.len == 4);
1807 assert(array[4] == 0);1807 assert(array[4] == 0);
1808}1808}
...@@ -1885,12 +1885,12 @@ test "address of syntax" {...@@ -1885,12 +1885,12 @@ test "address of syntax" {
1885 assert(x_ptr.* == 1234);1885 assert(x_ptr.* == 1234);
18861886
1887 // When you get the address of a const variable, you get a const pointer to a single item.1887 // When you get the address of a const variable, you get a const pointer to a single item.
1888 assert(@typeOf(x_ptr) == *const i32);1888 assert(@TypeOf(x_ptr) == *const i32);
18891889
1890 // If you want to mutate the value, you'd need an address of a mutable variable:1890 // If you want to mutate the value, you'd need an address of a mutable variable:
1891 var y: i32 = 5678;1891 var y: i32 = 5678;
1892 const y_ptr = &y;1892 const y_ptr = &y;
1893 assert(@typeOf(y_ptr) == *i32);1893 assert(@TypeOf(y_ptr) == *i32);
1894 y_ptr.* += 1;1894 y_ptr.* += 1;
1895 assert(y_ptr.* == 5679);1895 assert(y_ptr.* == 5679);
1896}1896}
...@@ -1901,7 +1901,7 @@ test "pointer array access" {...@@ -1901,7 +1901,7 @@ test "pointer array access" {
1901 // does not support pointer arithmetic.1901 // does not support pointer arithmetic.
1902 var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };1902 var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
1903 const ptr = &array[2];1903 const ptr = &array[2];
1904 assert(@typeOf(ptr) == *u8);1904 assert(@TypeOf(ptr) == *u8);
19051905
1906 assert(array[2] == 3);1906 assert(array[2] == 3);
1907 ptr.* += 1;1907 ptr.* += 1;
...@@ -1953,7 +1953,7 @@ const assert = @import("std").debug.assert;...@@ -1953,7 +1953,7 @@ const assert = @import("std").debug.assert;
1953test "@ptrToInt and @intToPtr" {1953test "@ptrToInt and @intToPtr" {
1954 const ptr = @intToPtr(*i32, 0xdeadbeef);1954 const ptr = @intToPtr(*i32, 0xdeadbeef);
1955 const addr = @ptrToInt(ptr);1955 const addr = @ptrToInt(ptr);
1956 assert(@typeOf(addr) == usize);1956 assert(@TypeOf(addr) == usize);
1957 assert(addr == 0xdeadbeef);1957 assert(addr == 0xdeadbeef);
1958}1958}
1959 {#code_end#}1959 {#code_end#}
...@@ -1968,7 +1968,7 @@ test "comptime @intToPtr" {...@@ -1968,7 +1968,7 @@ test "comptime @intToPtr" {
1968 // ptr is never dereferenced.1968 // ptr is never dereferenced.
1969 const ptr = @intToPtr(*i32, 0xdeadbeef);1969 const ptr = @intToPtr(*i32, 0xdeadbeef);
1970 const addr = @ptrToInt(ptr);1970 const addr = @ptrToInt(ptr);
1971 assert(@typeOf(addr) == usize);1971 assert(@TypeOf(addr) == usize);
1972 assert(addr == 0xdeadbeef);1972 assert(addr == 0xdeadbeef);
1973 }1973 }
1974}1974}
...@@ -1984,7 +1984,7 @@ const assert = @import("std").debug.assert;...@@ -1984,7 +1984,7 @@ const assert = @import("std").debug.assert;
19841984
1985test "volatile" {1985test "volatile" {
1986 const mmio_ptr = @intToPtr(*volatile u8, 0x12345678);1986 const mmio_ptr = @intToPtr(*volatile u8, 0x12345678);
1987 assert(@typeOf(mmio_ptr) == *volatile u8);1987 assert(@TypeOf(mmio_ptr) == *volatile u8);
1988}1988}
1989 {#code_end#}1989 {#code_end#}
1990 <p>1990 <p>
...@@ -2041,8 +2041,8 @@ const builtin = @import("builtin");...@@ -2041,8 +2041,8 @@ const builtin = @import("builtin");
20412041
2042test "variable alignment" {2042test "variable alignment" {
2043 var x: i32 = 1234;2043 var x: i32 = 1234;
2044 const align_of_i32 = @alignOf(@typeOf(x));2044 const align_of_i32 = @alignOf(@TypeOf(x));
2045 assert(@typeOf(&x) == *i32);2045 assert(@TypeOf(&x) == *i32);
2046 assert(*i32 == *align(align_of_i32) i32);2046 assert(*i32 == *align(align_of_i32) i32);
2047 if (builtin.arch == builtin.Arch.x86_64) {2047 if (builtin.arch == builtin.Arch.x86_64) {
2048 assert((*i32).alignment == 4);2048 assert((*i32).alignment == 4);
...@@ -2063,10 +2063,10 @@ const assert = @import("std").debug.assert;...@@ -2063,10 +2063,10 @@ const assert = @import("std").debug.assert;
2063var foo: u8 align(4) = 100;2063var foo: u8 align(4) = 100;
20642064
2065test "global variable alignment" {2065test "global variable alignment" {
2066 assert(@typeOf(&foo).alignment == 4);2066 assert(@TypeOf(&foo).alignment == 4);
2067 assert(@typeOf(&foo) == *align(4) u8);2067 assert(@TypeOf(&foo) == *align(4) u8);
2068 const slice = @as(*[1]u8, &foo)[0..];2068 const slice = @as(*[1]u8, &foo)[0..];
2069 assert(@typeOf(slice) == []align(4) u8);2069 assert(@TypeOf(slice) == []align(4) u8);
2070}2070}
20712071
2072fn derp() align(@sizeOf(usize) * 2) i32 { return 1234; }2072fn derp() align(@sizeOf(usize) * 2) i32 { return 1234; }
...@@ -2075,8 +2075,8 @@ fn noop4() align(4) void {}...@@ -2075,8 +2075,8 @@ fn noop4() align(4) void {}
20752075
2076test "function alignment" {2076test "function alignment" {
2077 assert(derp() == 1234);2077 assert(derp() == 1234);
2078 assert(@typeOf(noop1) == fn() align(1) void);2078 assert(@TypeOf(noop1) == fn() align(1) void);
2079 assert(@typeOf(noop4) == fn() align(4) void);2079 assert(@TypeOf(noop4) == fn() align(4) void);
2080 noop1();2080 noop1();
2081 noop4();2081 noop4();
2082}2082}
...@@ -2162,8 +2162,8 @@ test "basic slices" {...@@ -2162,8 +2162,8 @@ test "basic slices" {
21622162
2163 // Using the address-of operator on a slice gives a pointer to a single2163 // Using the address-of operator on a slice gives a pointer to a single
2164 // item, while using the `ptr` field gives an unknown length pointer.2164 // item, while using the `ptr` field gives an unknown length pointer.
2165 assert(@typeOf(slice.ptr) == [*]i32);2165 assert(@TypeOf(slice.ptr) == [*]i32);
2166 assert(@typeOf(&slice[0]) == *i32);2166 assert(@TypeOf(&slice[0]) == *i32);
2167 assert(@ptrToInt(slice.ptr) == @ptrToInt(&slice[0]));2167 assert(@ptrToInt(slice.ptr) == @ptrToInt(&slice[0]));
21682168
2169 // Slices have array bounds checking. If you try to access something out2169 // Slices have array bounds checking. If you try to access something out
...@@ -2208,7 +2208,7 @@ test "slice pointer" {...@@ -2208,7 +2208,7 @@ test "slice pointer" {
2208 slice[2] = 3;2208 slice[2] = 3;
2209 assert(slice[2] == 3);2209 assert(slice[2] == 3);
2210 // The slice is mutable because we sliced a mutable pointer.2210 // The slice is mutable because we sliced a mutable pointer.
2211 assert(@typeOf(slice) == []u8);2211 assert(@TypeOf(slice) == []u8);
22122212
2213 // You can also slice a slice:2213 // You can also slice a slice:
2214 const slice2 = slice[2..3];2214 const slice2 = slice[2..3];
...@@ -3566,7 +3566,7 @@ test "for basics" {...@@ -3566,7 +3566,7 @@ test "for basics" {
3566 // This is zero-indexed.3566 // This is zero-indexed.
3567 var sum2: i32 = 0;3567 var sum2: i32 = 0;
3568 for (items) |value, i| {3568 for (items) |value, i| {
3569 assert(@typeOf(i) == usize);3569 assert(@TypeOf(i) == usize);
3570 sum2 += @intCast(i32, i);3570 sum2 += @intCast(i32, i);
3571 }3571 }
3572 assert(sum2 == 10);3572 assert(sum2 == 10);
...@@ -3909,7 +3909,7 @@ test "type of unreachable" {...@@ -3909,7 +3909,7 @@ test "type of unreachable" {
3909 // However this assertion will still fail because3909 // However this assertion will still fail because
3910 // evaluating unreachable at compile-time is a compile error.3910 // evaluating unreachable at compile-time is a compile error.
39113911
3912 assert(@typeOf(unreachable) == noreturn);3912 assert(@TypeOf(unreachable) == noreturn);
3913 }3913 }
3914}3914}
3915 {#code_end#}3915 {#code_end#}
...@@ -4018,7 +4018,7 @@ test "function" {...@@ -4018,7 +4018,7 @@ test "function" {
4018const assert = @import("std").debug.assert;4018const assert = @import("std").debug.assert;
40194019
4020comptime {4020comptime {
4021 assert(@typeOf(foo) == fn()void);4021 assert(@TypeOf(foo) == fn()void);
4022 assert(@sizeOf(fn()void) == @sizeOf(?fn()void));4022 assert(@sizeOf(fn()void) == @sizeOf(?fn()void));
4023}4023}
40244024
...@@ -4062,35 +4062,35 @@ test "pass struct to function" {...@@ -4062,35 +4062,35 @@ test "pass struct to function" {
4062 </p>4062 </p>
4063 {#header_close#}4063 {#header_close#}
4064 {#header_open|Function Parameter Type Inference#}4064 {#header_open|Function Parameter Type Inference#}
4065 <p> 4065 <p>
4066 Function parameters can be declared with {#syntax#}var{#endsyntax#} in place of the type. 4066 Function parameters can be declared with {#syntax#}var{#endsyntax#} in place of the type.
4067 In this case the parameter types will be inferred when the function is called.4067 In this case the parameter types will be inferred when the function is called.
4068 Use {#link|@typeOf#} and {#link|@typeInfo#} to get information about the inferred type.4068 Use {#link|@TypeOf#} and {#link|@typeInfo#} to get information about the inferred type.
4069 </p>4069 </p>
4070 {#code_begin|test#}4070 {#code_begin|test#}
4071const assert = @import("std").debug.assert;4071const assert = @import("std").debug.assert;
40724072
4073fn addFortyTwo(x: var) @typeOf(x) {4073fn addFortyTwo(x: var) @TypeOf(x) {
4074 return x + 42;4074 return x + 42;
4075}4075}
40764076
4077test "fn type inference" {4077test "fn type inference" {
4078 assert(addFortyTwo(1) == 43);4078 assert(addFortyTwo(1) == 43);
4079 assert(@typeOf(addFortyTwo(1)) == comptime_int);4079 assert(@TypeOf(addFortyTwo(1)) == comptime_int);
4080 var y: i64 = 2;4080 var y: i64 = 2;
4081 assert(addFortyTwo(y) == 44);4081 assert(addFortyTwo(y) == 44);
4082 assert(@typeOf(addFortyTwo(y)) == i64);4082 assert(@TypeOf(addFortyTwo(y)) == i64);
4083}4083}
4084 {#code_end#}4084 {#code_end#}
4085 4085
4086 {#header_close#}4086 {#header_close#}
4087 {#header_open|Function Reflection#}4087 {#header_open|Function Reflection#}
4088 {#code_begin|test#}4088 {#code_begin|test#}
4089const assert = @import("std").debug.assert;4089const assert = @import("std").debug.assert;
40904090
4091test "fn reflection" {4091test "fn reflection" {
4092 assert(@typeOf(assert).ReturnType == void);4092 assert(@TypeOf(assert).ReturnType == void);
4093 assert(@typeOf(assert).is_var_args == false);4093 assert(@TypeOf(assert).is_var_args == false);
4094}4094}
4095 {#code_end#}4095 {#code_end#}
4096 {#header_close#}4096 {#header_close#}
...@@ -4390,10 +4390,10 @@ test "error union" {...@@ -4390,10 +4390,10 @@ test "error union" {
4390 foo = error.SomeError;4390 foo = error.SomeError;
43914391
4392 // Use compile-time reflection to access the payload type of an error union:4392 // Use compile-time reflection to access the payload type of an error union:
4393 comptime assert(@typeOf(foo).Payload == i32);4393 comptime assert(@TypeOf(foo).Payload == i32);
43944394
4395 // Use compile-time reflection to access the error set type of an error union:4395 // Use compile-time reflection to access the error set type of an error union:
4396 comptime assert(@typeOf(foo).ErrorSet == anyerror);4396 comptime assert(@TypeOf(foo).ErrorSet == anyerror);
4397}4397}
4398 {#code_end#}4398 {#code_end#}
4399 {#header_open|Merging Error Sets#}4399 {#header_open|Merging Error Sets#}
...@@ -4770,7 +4770,7 @@ test "optional type" {...@@ -4770,7 +4770,7 @@ test "optional type" {
4770 foo = 1234;4770 foo = 1234;
47714771
4772 // Use compile-time reflection to access the child type of the optional:4772 // Use compile-time reflection to access the child type of the optional:
4773 comptime assert(@typeOf(foo).Child == i32);4773 comptime assert(@TypeOf(foo).Child == i32);
4774}4774}
4775 {#code_end#}4775 {#code_end#}
4776 {#header_close#}4776 {#header_close#}
...@@ -5154,7 +5154,7 @@ test "peer resolve int widening" {...@@ -5154,7 +5154,7 @@ test "peer resolve int widening" {
5154 var b: i16 = 34;5154 var b: i16 = 34;
5155 var c = a + b;5155 var c = a + b;
5156 assert(c == 46);5156 assert(c == 46);
5157 assert(@typeOf(c) == i16);5157 assert(@TypeOf(c) == i16);
5158}5158}
51595159
5160test "peer resolve arrays of different size to const slice" {5160test "peer resolve arrays of different size to const slice" {
...@@ -5949,7 +5949,7 @@ pub fn printf(self: *OutStream, arg0: i32, arg1: []const u8) !void {...@@ -5949,7 +5949,7 @@ pub fn printf(self: *OutStream, arg0: i32, arg1: []const u8) !void {
5949 </p>5949 </p>
5950 {#code_begin|syntax#}5950 {#code_begin|syntax#}
5951pub fn printValue(self: *OutStream, value: var) !void {5951pub fn printValue(self: *OutStream, value: var) !void {
5952 const T = @typeOf(value);5952 const T = @TypeOf(value);
5953 if (@isInteger(T)) {5953 if (@isInteger(T)) {
5954 return self.printInt(T, value);5954 return self.printInt(T, value);
5955 } else if (@isFloat(T)) {5955 } else if (@isFloat(T)) {
...@@ -6265,7 +6265,7 @@ test "async function suspend with block" {...@@ -6265,7 +6265,7 @@ test "async function suspend with block" {
62656265
6266fn testSuspendBlock() void {6266fn testSuspendBlock() void {
6267 suspend {6267 suspend {
6268 comptime assert(@typeOf(@frame()) == *@Frame(testSuspendBlock));6268 comptime assert(@TypeOf(@frame()) == *@Frame(testSuspendBlock));
6269 the_frame = @frame();6269 the_frame = @frame();
6270 }6270 }
6271 result = true;6271 result = true;
...@@ -6332,7 +6332,7 @@ test "async and await" {...@@ -6332,7 +6332,7 @@ test "async and await" {
63326332
6333fn amain() void {6333fn amain() void {
6334 var frame = async func();6334 var frame = async func();
6335 comptime assert(@typeOf(frame) == @Frame(func));6335 comptime assert(@TypeOf(frame) == @Frame(func));
63366336
6337 const ptr: anyframe->void = &frame;6337 const ptr: anyframe->void = &frame;
6338 const any_ptr: anyframe = ptr;6338 const any_ptr: anyframe = ptr;
...@@ -6740,7 +6740,7 @@ async fn func(y: *i32) void {...@@ -6740,7 +6740,7 @@ async fn func(y: *i32) void {
6740 Converts a value of one type to another type.6740 Converts a value of one type to another type.
6741 </p>6741 </p>
6742 <p>6742 <p>
6743 Asserts that {#syntax#}@sizeOf(@typeOf(value)) == @sizeOf(DestType){#endsyntax#}.6743 Asserts that {#syntax#}@sizeOf(@TypeOf(value)) == @sizeOf(DestType){#endsyntax#}.
6744 </p>6744 </p>
6745 <p>6745 <p>
6746 Asserts that {#syntax#}@typeId(DestType) != @import("builtin").TypeId.Pointer{#endsyntax#}. Use {#syntax#}@ptrCast{#endsyntax#} or {#syntax#}@intToPtr{#endsyntax#} if you need this.6746 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...@@ -7045,7 +7045,7 @@ fn cmpxchgStrongButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_v
7045 <p>7045 <p>
7046 {#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("builtin").AtomicOrder{#endsyntax#}.7046 {#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("builtin").AtomicOrder{#endsyntax#}.
7047 </p>7047 </p>
7048 <p>{#syntax#}@typeOf(ptr).alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>7048 <p>{#syntax#}@TypeOf(ptr).alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>
7049 {#see_also|Compile Variables|cmpxchgWeak#}7049 {#see_also|Compile Variables|cmpxchgWeak#}
7050 {#header_close#}7050 {#header_close#}
7051 {#header_open|@cmpxchgWeak#}7051 {#header_open|@cmpxchgWeak#}
...@@ -7073,7 +7073,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val...@@ -7073,7 +7073,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
7073 <p>7073 <p>
7074 {#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("builtin").AtomicOrder{#endsyntax#}.7074 {#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("builtin").AtomicOrder{#endsyntax#}.
7075 </p>7075 </p>
7076 <p>{#syntax#}@typeOf(ptr).alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>7076 <p>{#syntax#}@TypeOf(ptr).alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>
7077 {#see_also|Compile Variables|cmpxchgStrong#}7077 {#see_also|Compile Variables|cmpxchgStrong#}
7078 {#header_close#}7078 {#header_close#}
70797079
...@@ -8020,7 +8020,7 @@ test "@setRuntimeSafety" {...@@ -8020,7 +8020,7 @@ test "@setRuntimeSafety" {
8020 {#header_close#}8020 {#header_close#}
80218021
8022 {#header_open|@splat#}8022 {#header_open|@splat#}
8023 <pre>{#syntax#}@splat(comptime len: u32, scalar: var) @Vector(len, @typeOf(scalar)){#endsyntax#}</pre>8023 <pre>{#syntax#}@splat(comptime len: u32, scalar: var) @Vector(len, @TypeOf(scalar)){#endsyntax#}</pre>
8024 <p>8024 <p>
8025 Produces a vector of length {#syntax#}len{#endsyntax#} where each element is the value8025 Produces a vector of length {#syntax#}len{#endsyntax#} where each element is the value
8026 {#syntax#}scalar{#endsyntax#}:8026 {#syntax#}scalar{#endsyntax#}:
...@@ -8032,7 +8032,7 @@ const assert = std.debug.assert;...@@ -8032,7 +8032,7 @@ const assert = std.debug.assert;
8032test "vector @splat" {8032test "vector @splat" {
8033 const scalar: u32 = 5;8033 const scalar: u32 = 5;
8034 const result = @splat(4, scalar);8034 const result = @splat(4, scalar);
8035 comptime assert(@typeOf(result) == @Vector(4, u32));8035 comptime assert(@TypeOf(result) == @Vector(4, u32));
8036 assert(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));8036 assert(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
8037}8037}
8038 {#code_end#}8038 {#code_end#}
...@@ -8250,8 +8250,8 @@ test "integer truncation" {...@@ -8250,8 +8250,8 @@ test "integer truncation" {
8250 <li>{#link|Pointers#}</li>8250 <li>{#link|Pointers#}</li>
8251 <li>{#syntax#}comptime_int{#endsyntax#}</li>8251 <li>{#syntax#}comptime_int{#endsyntax#}</li>
8252 <li>{#syntax#}comptime_float{#endsyntax#}</li>8252 <li>{#syntax#}comptime_float{#endsyntax#}</li>
8253 <li>{#syntax#}@typeOf(undefined){#endsyntax#}</li>8253 <li>{#syntax#}@TypeOf(undefined){#endsyntax#}</li>
8254 <li>{#syntax#}@typeOf(null){#endsyntax#}</li>8254 <li>{#syntax#}@TypeOf(null){#endsyntax#}</li>
8255 </ul>8255 </ul>
8256 <p>8256 <p>
8257 For these types it is a8257 For these types it is a
...@@ -8516,20 +8516,20 @@ pub const TypeInfo = union(TypeId) {...@@ -8516,20 +8516,20 @@ pub const TypeInfo = union(TypeId) {
85168516
8517 {#header_close#}8517 {#header_close#}
85188518
8519 {#header_open|@typeOf#}8519 {#header_open|@TypeOf#}
8520 <pre>{#syntax#}@typeOf(expression) type{#endsyntax#}</pre>8520 <pre>{#syntax#}@TypeOf(expression) type{#endsyntax#}</pre>
8521 <p>8521 <p>
8522 This function returns a compile-time constant, which is the type of the8522 This function returns a compile-time constant, which is the type of the
8523 expression passed as an argument. The expression is evaluated.8523 expression passed as an argument. The expression is evaluated.
8524 </p>8524 </p>
8525 <p>{#syntax#}@typeOf{#endsyntax#} guarantees no run-time side-effects within the expression:</p>8525 <p>{#syntax#}@TypeOf{#endsyntax#} guarantees no run-time side-effects within the expression:</p>
8526 {#code_begin|test#}8526 {#code_begin|test#}
8527const std = @import("std");8527const std = @import("std");
8528const assert = std.debug.assert;8528const assert = std.debug.assert;
85298529
8530test "no runtime side effects" {8530test "no runtime side effects" {
8531 var data: i32 = 0;8531 var data: i32 = 0;
8532 const T = @typeOf(foo(i32, &data));8532 const T = @TypeOf(foo(i32, &data));
8533 comptime assert(T == i32);8533 comptime assert(T == i32);
8534 assert(data == 0);8534 assert(data == 0);
8535}8535}
lib/std/array_list.zig+1-1
...@@ -40,7 +40,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {...@@ -40,7 +40,7 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {
40 .allocator = allocator,40 .allocator = allocator,
41 };41 };
42 }42 }
43 43
44 /// Initialize with capacity to hold at least num elements.44 /// Initialize with capacity to hold at least num elements.
45 /// Deinitialize with `deinit` or use `toOwnedSlice`.45 /// Deinitialize with `deinit` or use `toOwnedSlice`.
46 pub fn initCapacity(allocator: *Allocator, num: usize) !Self {46 pub fn initCapacity(allocator: *Allocator, num: usize) !Self {
lib/std/atomic/queue.zig+1-1
...@@ -106,7 +106,7 @@ pub fn Queue(comptime T: type) type {...@@ -106,7 +106,7 @@ pub fn Queue(comptime T: type) type {
106 pub fn dump(self: *Self) void {106 pub fn dump(self: *Self) void {
107 var stderr_file = std.io.getStdErr() catch return;107 var stderr_file = std.io.getStdErr() catch return;
108 const stderr = &stderr_file.outStream().stream;108 const stderr = &stderr_file.outStream().stream;
109 const Error = @typeInfo(@typeOf(stderr)).Pointer.child.Error;109 const Error = @typeInfo(@TypeOf(stderr)).Pointer.child.Error;
110110
111 self.dumpToStream(Error, stderr) catch return;111 self.dumpToStream(Error, stderr) catch return;
112 }112 }
lib/std/atomic/stack.zig+1-1
...@@ -9,7 +9,7 @@ const expect = std.testing.expect;...@@ -9,7 +9,7 @@ const expect = std.testing.expect;
9pub fn Stack(comptime T: type) type {9pub fn Stack(comptime T: type) type {
10 return struct {10 return struct {
11 root: ?*Node,11 root: ?*Node,
12 lock: @typeOf(lock_init),12 lock: @TypeOf(lock_init),
1313
14 const lock_init = if (builtin.single_threaded) {} else @as(u8, 0);14 const lock_init = if (builtin.single_threaded) {} else @as(u8, 0);
1515
lib/std/debug.zig+4-4
...@@ -1290,7 +1290,7 @@ pub const DwarfInfo = struct {...@@ -1290,7 +1290,7 @@ pub const DwarfInfo = struct {
1290 try di.dwarf_seekable_stream.seekTo(this_unit_offset);1290 try di.dwarf_seekable_stream.seekTo(this_unit_offset);
12911291
1292 var is_64: bool = undefined;1292 var is_64: bool = undefined;
1293 const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);1293 const unit_length = try readInitialLength(@TypeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
1294 if (unit_length == 0) return;1294 if (unit_length == 0) return;
1295 const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));1295 const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));
12961296
...@@ -1392,7 +1392,7 @@ pub const DwarfInfo = struct {...@@ -1392,7 +1392,7 @@ pub const DwarfInfo = struct {
1392 try di.dwarf_seekable_stream.seekTo(this_unit_offset);1392 try di.dwarf_seekable_stream.seekTo(this_unit_offset);
13931393
1394 var is_64: bool = undefined;1394 var is_64: bool = undefined;
1395 const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);1395 const unit_length = try readInitialLength(@TypeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
1396 if (unit_length == 0) return;1396 if (unit_length == 0) return;
1397 const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));1397 const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));
13981398
...@@ -1551,7 +1551,7 @@ pub const DwarfInfo = struct {...@@ -1551,7 +1551,7 @@ pub const DwarfInfo = struct {
1551 try di.dwarf_seekable_stream.seekTo(di.debug_line.offset + line_info_offset);1551 try di.dwarf_seekable_stream.seekTo(di.debug_line.offset + line_info_offset);
15521552
1553 var is_64: bool = undefined;1553 var is_64: bool = undefined;
1554 const unit_length = try readInitialLength(@typeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);1554 const unit_length = try readInitialLength(@TypeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);
1555 if (unit_length == 0) {1555 if (unit_length == 0) {
1556 return error.MissingDebugInfo;1556 return error.MissingDebugInfo;
1557 }1557 }
...@@ -2080,7 +2080,7 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64...@@ -2080,7 +2080,7 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64
2080 DW.FORM_strp => FormValue{ .StrPtr = try parseFormValueDwarfOffsetSize(in_stream, is_64) },2080 DW.FORM_strp => FormValue{ .StrPtr = try parseFormValueDwarfOffsetSize(in_stream, is_64) },
2081 DW.FORM_indirect => {2081 DW.FORM_indirect => {
2082 const child_form_id = try noasync leb.readULEB128(u64, in_stream);2082 const child_form_id = try noasync leb.readULEB128(u64, in_stream);
2083 const F = @typeOf(async parseFormValue(allocator, in_stream, child_form_id, is_64));2083 const F = @TypeOf(async parseFormValue(allocator, in_stream, child_form_id, is_64));
2084 var frame = try allocator.create(F);2084 var frame = try allocator.create(F);
2085 defer allocator.destroy(frame);2085 defer allocator.destroy(frame);
2086 return await @asyncCall(frame, {}, parseFormValue, allocator, in_stream, child_form_id, is_64);2086 return await @asyncCall(frame, {}, parseFormValue, allocator, in_stream, child_form_id, is_64);
lib/std/event/group.zig+1-1
...@@ -61,7 +61,7 @@ pub fn Group(comptime ReturnType: type) type {...@@ -61,7 +61,7 @@ pub fn Group(comptime ReturnType: type) type {
61 /// `func` must be async and have return type `ReturnType`.61 /// `func` must be async and have return type `ReturnType`.
62 /// Thread-safe.62 /// Thread-safe.
63 pub fn call(self: *Self, comptime func: var, args: var) error{OutOfMemory}!void {63 pub fn call(self: *Self, comptime func: var, args: var) error{OutOfMemory}!void {
64 var frame = try self.allocator.create(@typeOf(@call(.{ .modifier = .async_kw }, func, args)));64 var frame = try self.allocator.create(@TypeOf(@call(.{ .modifier = .async_kw }, func, args)));
65 errdefer self.allocator.destroy(frame);65 errdefer self.allocator.destroy(frame);
66 const node = try self.allocator.create(AllocStack.Node);66 const node = try self.allocator.create(AllocStack.Node);
67 errdefer self.allocator.destroy(node);67 errdefer self.allocator.destroy(node);
lib/std/event/loop.zig+1-1
...@@ -42,7 +42,7 @@ pub const Loop = struct {...@@ -42,7 +42,7 @@ pub const Loop = struct {
42 },42 },
43 else => {},43 else => {},
44 };44 };
45 pub const Overlapped = @typeOf(overlapped_init);45 pub const Overlapped = @TypeOf(overlapped_init);
4646
47 pub const Id = enum {47 pub const Id = enum {
48 Basic,48 Basic,
lib/std/fmt.zig+34-34
...@@ -80,7 +80,7 @@ fn peekIsAlign(comptime fmt: []const u8) bool {...@@ -80,7 +80,7 @@ fn peekIsAlign(comptime fmt: []const u8) bool {
80///80///
81/// If a formatted user type contains a function of the type81/// If a formatted user type contains a function of the type
82/// ```82/// ```
83/// 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!void83/// 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
84/// ```84/// ```
85/// with `?` being the type formatted, this function will be called instead of the default implementation.85/// with `?` being the type formatted, this function will be called instead of the default implementation.
86/// This allows user types to be formatted in a logical manner instead of dumping all fields of the type.86/// 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 {...@@ -89,7 +89,7 @@ fn peekIsAlign(comptime fmt: []const u8) bool {
89pub fn format(89pub fn format(
90 context: var,90 context: var,
91 comptime Errors: type,91 comptime Errors: type,
92 output: fn (@typeOf(context), []const u8) Errors!void,92 output: fn (@TypeOf(context), []const u8) Errors!void,
93 comptime fmt: []const u8,93 comptime fmt: []const u8,
94 args: var,94 args: var,
95) Errors!void {95) Errors!void {
...@@ -320,17 +320,17 @@ pub fn formatType(...@@ -320,17 +320,17 @@ pub fn formatType(
320 options: FormatOptions,320 options: FormatOptions,
321 context: var,321 context: var,
322 comptime Errors: type,322 comptime Errors: type,
323 output: fn (@typeOf(context), []const u8) Errors!void,323 output: fn (@TypeOf(context), []const u8) Errors!void,
324 max_depth: usize,324 max_depth: usize,
325) Errors!void {325) Errors!void {
326 if (comptime std.mem.eql(u8, fmt, "*")) {326 if (comptime std.mem.eql(u8, fmt, "*")) {
327 try output(context, @typeName(@typeOf(value).Child));327 try output(context, @typeName(@TypeOf(value).Child));
328 try output(context, "@");328 try output(context, "@");
329 try formatInt(@ptrToInt(value), 16, false, FormatOptions{}, context, Errors, output);329 try formatInt(@ptrToInt(value), 16, false, FormatOptions{}, context, Errors, output);
330 return;330 return;
331 }331 }
332332
333 const T = @typeOf(value);333 const T = @TypeOf(value);
334 switch (@typeInfo(T)) {334 switch (@typeInfo(T)) {
335 .ComptimeInt, .Int, .Float => {335 .ComptimeInt, .Int, .Float => {
336 return formatValue(value, fmt, options, context, Errors, output);336 return formatValue(value, fmt, options, context, Errors, output);
...@@ -478,7 +478,7 @@ fn formatValue(...@@ -478,7 +478,7 @@ fn formatValue(
478 options: FormatOptions,478 options: FormatOptions,
479 context: var,479 context: var,
480 comptime Errors: type,480 comptime Errors: type,
481 output: fn (@typeOf(context), []const u8) Errors!void,481 output: fn (@TypeOf(context), []const u8) Errors!void,
482) Errors!void {482) Errors!void {
483 if (comptime std.mem.eql(u8, fmt, "B")) {483 if (comptime std.mem.eql(u8, fmt, "B")) {
484 return formatBytes(value, options, 1000, context, Errors, output);484 return formatBytes(value, options, 1000, context, Errors, output);
...@@ -486,7 +486,7 @@ fn formatValue(...@@ -486,7 +486,7 @@ fn formatValue(
486 return formatBytes(value, options, 1024, context, Errors, output);486 return formatBytes(value, options, 1024, context, Errors, output);
487 }487 }
488488
489 const T = @typeOf(value);489 const T = @TypeOf(value);
490 switch (@typeId(T)) {490 switch (@typeId(T)) {
491 .Float => return formatFloatValue(value, fmt, options, context, Errors, output),491 .Float => return formatFloatValue(value, fmt, options, context, Errors, output),
492 .Int, .ComptimeInt => return formatIntValue(value, fmt, options, context, Errors, output),492 .Int, .ComptimeInt => return formatIntValue(value, fmt, options, context, Errors, output),
...@@ -500,12 +500,12 @@ pub fn formatIntValue(...@@ -500,12 +500,12 @@ pub fn formatIntValue(
500 options: FormatOptions,500 options: FormatOptions,
501 context: var,501 context: var,
502 comptime Errors: type,502 comptime Errors: type,
503 output: fn (@typeOf(context), []const u8) Errors!void,503 output: fn (@TypeOf(context), []const u8) Errors!void,
504) Errors!void {504) Errors!void {
505 comptime var radix = 10;505 comptime var radix = 10;
506 comptime var uppercase = false;506 comptime var uppercase = false;
507507
508 const int_value = if (@typeOf(value) == comptime_int) blk: {508 const int_value = if (@TypeOf(value) == comptime_int) blk: {
509 const Int = math.IntFittingRange(value, value);509 const Int = math.IntFittingRange(value, value);
510 break :blk @as(Int, value);510 break :blk @as(Int, value);
511 } else511 } else
...@@ -515,7 +515,7 @@ pub fn formatIntValue(...@@ -515,7 +515,7 @@ pub fn formatIntValue(
515 radix = 10;515 radix = 10;
516 uppercase = false;516 uppercase = false;
517 } else if (comptime std.mem.eql(u8, fmt, "c")) {517 } else if (comptime std.mem.eql(u8, fmt, "c")) {
518 if (@typeOf(int_value).bit_count <= 8) {518 if (@TypeOf(int_value).bit_count <= 8) {
519 return formatAsciiChar(@as(u8, int_value), options, context, Errors, output);519 return formatAsciiChar(@as(u8, int_value), options, context, Errors, output);
520 } else {520 } else {
521 @compileError("Cannot print integer that is larger than 8 bits as a ascii");521 @compileError("Cannot print integer that is larger than 8 bits as a ascii");
...@@ -542,7 +542,7 @@ fn formatFloatValue(...@@ -542,7 +542,7 @@ fn formatFloatValue(
542 options: FormatOptions,542 options: FormatOptions,
543 context: var,543 context: var,
544 comptime Errors: type,544 comptime Errors: type,
545 output: fn (@typeOf(context), []const u8) Errors!void,545 output: fn (@TypeOf(context), []const u8) Errors!void,
546) Errors!void {546) Errors!void {
547 if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "e")) {547 if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "e")) {
548 return formatFloatScientific(value, options, context, Errors, output);548 return formatFloatScientific(value, options, context, Errors, output);
...@@ -559,7 +559,7 @@ pub fn formatText(...@@ -559,7 +559,7 @@ pub fn formatText(
559 options: FormatOptions,559 options: FormatOptions,
560 context: var,560 context: var,
561 comptime Errors: type,561 comptime Errors: type,
562 output: fn (@typeOf(context), []const u8) Errors!void,562 output: fn (@TypeOf(context), []const u8) Errors!void,
563) Errors!void {563) Errors!void {
564 if (fmt.len == 0) {564 if (fmt.len == 0) {
565 return output(context, bytes);565 return output(context, bytes);
...@@ -580,7 +580,7 @@ pub fn formatAsciiChar(...@@ -580,7 +580,7 @@ pub fn formatAsciiChar(
580 options: FormatOptions,580 options: FormatOptions,
581 context: var,581 context: var,
582 comptime Errors: type,582 comptime Errors: type,
583 output: fn (@typeOf(context), []const u8) Errors!void,583 output: fn (@TypeOf(context), []const u8) Errors!void,
584) Errors!void {584) Errors!void {
585 return output(context, @as(*const [1]u8, &c)[0..]);585 return output(context, @as(*const [1]u8, &c)[0..]);
586}586}
...@@ -590,7 +590,7 @@ pub fn formatBuf(...@@ -590,7 +590,7 @@ pub fn formatBuf(
590 options: FormatOptions,590 options: FormatOptions,
591 context: var,591 context: var,
592 comptime Errors: type,592 comptime Errors: type,
593 output: fn (@typeOf(context), []const u8) Errors!void,593 output: fn (@TypeOf(context), []const u8) Errors!void,
594) Errors!void {594) Errors!void {
595 try output(context, buf);595 try output(context, buf);
596596
...@@ -610,7 +610,7 @@ pub fn formatFloatScientific(...@@ -610,7 +610,7 @@ pub fn formatFloatScientific(
610 options: FormatOptions,610 options: FormatOptions,
611 context: var,611 context: var,
612 comptime Errors: type,612 comptime Errors: type,
613 output: fn (@typeOf(context), []const u8) Errors!void,613 output: fn (@TypeOf(context), []const u8) Errors!void,
614) Errors!void {614) Errors!void {
615 var x = @floatCast(f64, value);615 var x = @floatCast(f64, value);
616616
...@@ -672,7 +672,7 @@ pub fn formatFloatScientific(...@@ -672,7 +672,7 @@ pub fn formatFloatScientific(
672 try output(context, float_decimal.digits[0..1]);672 try output(context, float_decimal.digits[0..1]);
673 try output(context, ".");673 try output(context, ".");
674 if (float_decimal.digits.len > 1) {674 if (float_decimal.digits.len > 1) {
675 const num_digits = if (@typeOf(value) == f32) math.min(@as(usize, 9), float_decimal.digits.len) else float_decimal.digits.len;675 const num_digits = if (@TypeOf(value) == f32) math.min(@as(usize, 9), float_decimal.digits.len) else float_decimal.digits.len;
676676
677 try output(context, float_decimal.digits[1..num_digits]);677 try output(context, float_decimal.digits[1..num_digits]);
678 } else {678 } else {
...@@ -705,7 +705,7 @@ pub fn formatFloatDecimal(...@@ -705,7 +705,7 @@ pub fn formatFloatDecimal(
705 options: FormatOptions,705 options: FormatOptions,
706 context: var,706 context: var,
707 comptime Errors: type,707 comptime Errors: type,
708 output: fn (@typeOf(context), []const u8) Errors!void,708 output: fn (@TypeOf(context), []const u8) Errors!void,
709) Errors!void {709) Errors!void {
710 var x = @as(f64, value);710 var x = @as(f64, value);
711711
...@@ -851,7 +851,7 @@ pub fn formatBytes(...@@ -851,7 +851,7 @@ pub fn formatBytes(
851 comptime radix: usize,851 comptime radix: usize,
852 context: var,852 context: var,
853 comptime Errors: type,853 comptime Errors: type,
854 output: fn (@typeOf(context), []const u8) Errors!void,854 output: fn (@TypeOf(context), []const u8) Errors!void,
855) Errors!void {855) Errors!void {
856 if (value == 0) {856 if (value == 0) {
857 return output(context, "0B");857 return output(context, "0B");
...@@ -892,15 +892,15 @@ pub fn formatInt(...@@ -892,15 +892,15 @@ pub fn formatInt(
892 options: FormatOptions,892 options: FormatOptions,
893 context: var,893 context: var,
894 comptime Errors: type,894 comptime Errors: type,
895 output: fn (@typeOf(context), []const u8) Errors!void,895 output: fn (@TypeOf(context), []const u8) Errors!void,
896) Errors!void {896) Errors!void {
897 const int_value = if (@typeOf(value) == comptime_int) blk: {897 const int_value = if (@TypeOf(value) == comptime_int) blk: {
898 const Int = math.IntFittingRange(value, value);898 const Int = math.IntFittingRange(value, value);
899 break :blk @as(Int, value);899 break :blk @as(Int, value);
900 } else900 } else
901 value;901 value;
902902
903 if (@typeOf(int_value).is_signed) {903 if (@TypeOf(int_value).is_signed) {
904 return formatIntSigned(int_value, base, uppercase, options, context, Errors, output);904 return formatIntSigned(int_value, base, uppercase, options, context, Errors, output);
905 } else {905 } else {
906 return formatIntUnsigned(int_value, base, uppercase, options, context, Errors, output);906 return formatIntUnsigned(int_value, base, uppercase, options, context, Errors, output);
...@@ -914,7 +914,7 @@ fn formatIntSigned(...@@ -914,7 +914,7 @@ fn formatIntSigned(
914 options: FormatOptions,914 options: FormatOptions,
915 context: var,915 context: var,
916 comptime Errors: type,916 comptime Errors: type,
917 output: fn (@typeOf(context), []const u8) Errors!void,917 output: fn (@TypeOf(context), []const u8) Errors!void,
918) Errors!void {918) Errors!void {
919 const new_options = FormatOptions{919 const new_options = FormatOptions{
920 .width = if (options.width) |w| (if (w == 0) 0 else w - 1) else null,920 .width = if (options.width) |w| (if (w == 0) 0 else w - 1) else null,
...@@ -922,7 +922,7 @@ fn formatIntSigned(...@@ -922,7 +922,7 @@ fn formatIntSigned(
922 .fill = options.fill,922 .fill = options.fill,
923 };923 };
924924
925 const uint = @IntType(false, @typeOf(value).bit_count);925 const uint = @IntType(false, @TypeOf(value).bit_count);
926 if (value < 0) {926 if (value < 0) {
927 const minus_sign: u8 = '-';927 const minus_sign: u8 = '-';
928 try output(context, @as(*const [1]u8, &minus_sign)[0..]);928 try output(context, @as(*const [1]u8, &minus_sign)[0..]);
...@@ -945,12 +945,12 @@ fn formatIntUnsigned(...@@ -945,12 +945,12 @@ fn formatIntUnsigned(
945 options: FormatOptions,945 options: FormatOptions,
946 context: var,946 context: var,
947 comptime Errors: type,947 comptime Errors: type,
948 output: fn (@typeOf(context), []const u8) Errors!void,948 output: fn (@TypeOf(context), []const u8) Errors!void,
949) Errors!void {949) Errors!void {
950 assert(base >= 2);950 assert(base >= 2);
951 var buf: [math.max(@typeOf(value).bit_count, 1)]u8 = undefined;951 var buf: [math.max(@TypeOf(value).bit_count, 1)]u8 = undefined;
952 const min_int_bits = comptime math.max(@typeOf(value).bit_count, @typeOf(base).bit_count);952 const min_int_bits = comptime math.max(@TypeOf(value).bit_count, @TypeOf(base).bit_count);
953 const MinInt = @IntType(@typeOf(value).is_signed, min_int_bits);953 const MinInt = @IntType(@TypeOf(value).is_signed, min_int_bits);
954 var a: MinInt = value;954 var a: MinInt = value;
955 var index: usize = buf.len;955 var index: usize = buf.len;
956956
...@@ -1420,7 +1420,7 @@ test "custom" {...@@ -1420,7 +1420,7 @@ test "custom" {
1420 options: FormatOptions,1420 options: FormatOptions,
1421 context: var,1421 context: var,
1422 comptime Errors: type,1422 comptime Errors: type,
1423 output: fn (@typeOf(context), []const u8) Errors!void,1423 output: fn (@TypeOf(context), []const u8) Errors!void,
1424 ) Errors!void {1424 ) Errors!void {
1425 if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "p")) {1425 if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "p")) {
1426 return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y });1426 return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y });
...@@ -1610,7 +1610,7 @@ test "formatIntValue with comptime_int" {...@@ -1610,7 +1610,7 @@ test "formatIntValue with comptime_int" {
1610 const value: comptime_int = 123456789123456789;1610 const value: comptime_int = 123456789123456789;
16111611
1612 var buf = try std.Buffer.init(std.debug.global_allocator, "");1612 var buf = try std.Buffer.init(std.debug.global_allocator, "");
1613 try formatIntValue(value, "", FormatOptions{}, &buf, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append);1613 try formatIntValue(value, "", FormatOptions{}, &buf, @TypeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append);
1614 std.testing.expect(mem.eql(u8, buf.toSlice(), "123456789123456789"));1614 std.testing.expect(mem.eql(u8, buf.toSlice(), "123456789123456789"));
1615}1615}
16161616
...@@ -1626,7 +1626,7 @@ test "formatType max_depth" {...@@ -1626,7 +1626,7 @@ test "formatType max_depth" {
1626 options: FormatOptions,1626 options: FormatOptions,
1627 context: var,1627 context: var,
1628 comptime Errors: type,1628 comptime Errors: type,
1629 output: fn (@typeOf(context), []const u8) Errors!void,1629 output: fn (@TypeOf(context), []const u8) Errors!void,
1630 ) Errors!void {1630 ) Errors!void {
1631 if (fmt.len == 0) {1631 if (fmt.len == 0) {
1632 return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y });1632 return std.fmt.format(context, Errors, output, "({d:.3},{d:.3})", .{ self.x, self.y });
...@@ -1664,19 +1664,19 @@ test "formatType max_depth" {...@@ -1664,19 +1664,19 @@ test "formatType max_depth" {
1664 inst.tu.ptr = &inst.tu;1664 inst.tu.ptr = &inst.tu;
16651665
1666 var buf0 = try std.Buffer.init(std.debug.global_allocator, "");1666 var buf0 = try std.Buffer.init(std.debug.global_allocator, "");
1667 try formatType(inst, "", FormatOptions{}, &buf0, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 0);1667 try formatType(inst, "", FormatOptions{}, &buf0, @TypeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 0);
1668 std.testing.expect(mem.eql(u8, buf0.toSlice(), "S{ ... }"));1668 std.testing.expect(mem.eql(u8, buf0.toSlice(), "S{ ... }"));
16691669
1670 var buf1 = try std.Buffer.init(std.debug.global_allocator, "");1670 var buf1 = try std.Buffer.init(std.debug.global_allocator, "");
1671 try formatType(inst, "", FormatOptions{}, &buf1, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 1);1671 try formatType(inst, "", FormatOptions{}, &buf1, @TypeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 1);
1672 std.testing.expect(mem.eql(u8, buf1.toSlice(), "S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }"));1672 std.testing.expect(mem.eql(u8, buf1.toSlice(), "S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }"));
16731673
1674 var buf2 = try std.Buffer.init(std.debug.global_allocator, "");1674 var buf2 = try std.Buffer.init(std.debug.global_allocator, "");
1675 try formatType(inst, "", FormatOptions{}, &buf2, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 2);1675 try formatType(inst, "", FormatOptions{}, &buf2, @TypeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 2);
1676 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) }"));1676 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) }"));
16771677
1678 var buf3 = try std.Buffer.init(std.debug.global_allocator, "");1678 var buf3 = try std.Buffer.init(std.debug.global_allocator, "");
1679 try formatType(inst, "", FormatOptions{}, &buf3, @typeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 3);1679 try formatType(inst, "", FormatOptions{}, &buf3, @TypeOf(std.Buffer.append).ReturnType.ErrorSet, std.Buffer.append, 3);
1680 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) }"));1680 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) }"));
1681}1681}
16821682
lib/std/hash/auto_hash.zig+3-3
...@@ -22,7 +22,7 @@ pub const HashStrategy = enum {...@@ -22,7 +22,7 @@ pub const HashStrategy = enum {
2222
23/// Helper function to hash a pointer and mutate the strategy if needed.23/// Helper function to hash a pointer and mutate the strategy if needed.
24pub fn hashPointer(hasher: var, key: var, comptime strat: HashStrategy) void {24pub fn hashPointer(hasher: var, key: var, comptime strat: HashStrategy) void {
25 const info = @typeInfo(@typeOf(key));25 const info = @typeInfo(@TypeOf(key));
2626
27 switch (info.Pointer.size) {27 switch (info.Pointer.size) {
28 builtin.TypeInfo.Pointer.Size.One => switch (strat) {28 builtin.TypeInfo.Pointer.Size.One => switch (strat) {
...@@ -74,7 +74,7 @@ pub fn hashArray(hasher: var, key: var, comptime strat: HashStrategy) void {...@@ -74,7 +74,7 @@ pub fn hashArray(hasher: var, key: var, comptime strat: HashStrategy) void {
74/// Provides generic hashing for any eligible type.74/// Provides generic hashing for any eligible type.
75/// Strategy is provided to determine if pointers should be followed or not.75/// Strategy is provided to determine if pointers should be followed or not.
76pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void {76pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void {
77 const Key = @typeOf(key);77 const Key = @TypeOf(key);
78 switch (@typeInfo(Key)) {78 switch (@typeInfo(Key)) {
79 .NoReturn,79 .NoReturn,
80 .Opaque,80 .Opaque,
...@@ -164,7 +164,7 @@ pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void {...@@ -164,7 +164,7 @@ pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void {
164/// Only hashes `key` itself, pointers are not followed.164/// Only hashes `key` itself, pointers are not followed.
165/// Slices are rejected to avoid ambiguity on the user's intention.165/// Slices are rejected to avoid ambiguity on the user's intention.
166pub fn autoHash(hasher: var, key: var) void {166pub fn autoHash(hasher: var, key: var) void {
167 const Key = @typeOf(key);167 const Key = @TypeOf(key);
168 if (comptime meta.trait.isSlice(Key)) {168 if (comptime meta.trait.isSlice(Key)) {
169 comptime assert(@hasDecl(std, "StringHashMap")); // detect when the following message needs updated169 comptime assert(@hasDecl(std, "StringHashMap")); // detect when the following message needs updated
170 const extra_help = if (Key == []const u8)170 const extra_help = if (Key == []const u8)
lib/std/hash/cityhash.zig+4-4
...@@ -360,9 +360,9 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {...@@ -360,9 +360,9 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
360 var hashes: [hashbytes * 256]u8 = undefined;360 var hashes: [hashbytes * 256]u8 = undefined;
361 var final: [hashbytes]u8 = undefined;361 var final: [hashbytes]u8 = undefined;
362362
363 @memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@typeOf(key)));363 @memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@TypeOf(key)));
364 @memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@typeOf(hashes)));364 @memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@TypeOf(hashes)));
365 @memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@typeOf(final)));365 @memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@TypeOf(final)));
366366
367 var i: u32 = 0;367 var i: u32 = 0;
368 while (i < 256) : (i += 1) {368 while (i < 256) : (i += 1) {
...@@ -370,7 +370,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {...@@ -370,7 +370,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
370370
371 var h = hash_fn(key[0..i], 256 - i);371 var h = hash_fn(key[0..i], 256 - i);
372 if (builtin.endian == builtin.Endian.Big)372 if (builtin.endian == builtin.Endian.Big)
373 h = @byteSwap(@typeOf(h), h);373 h = @byteSwap(@TypeOf(h), h);
374 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);374 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
375 }375 }
376376
lib/std/hash/murmur.zig+4-4
...@@ -285,9 +285,9 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {...@@ -285,9 +285,9 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
285 var hashes: [hashbytes * 256]u8 = undefined;285 var hashes: [hashbytes * 256]u8 = undefined;
286 var final: [hashbytes]u8 = undefined;286 var final: [hashbytes]u8 = undefined;
287287
288 @memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@typeOf(key)));288 @memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@TypeOf(key)));
289 @memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@typeOf(hashes)));289 @memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@TypeOf(hashes)));
290 @memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@typeOf(final)));290 @memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@TypeOf(final)));
291291
292 var i: u32 = 0;292 var i: u32 = 0;
293 while (i < 256) : (i += 1) {293 while (i < 256) : (i += 1) {
...@@ -295,7 +295,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {...@@ -295,7 +295,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 {
295295
296 var h = hash_fn(key[0..i], 256 - i);296 var h = hash_fn(key[0..i], 256 - i);
297 if (builtin.endian == builtin.Endian.Big)297 if (builtin.endian == builtin.Endian.Big)
298 h = @byteSwap(@typeOf(h), h);298 h = @byteSwap(@TypeOf(h), h);
299 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);299 @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes);
300 }300 }
301301
lib/std/http/headers.zig+1-1
...@@ -367,7 +367,7 @@ pub const Headers = struct {...@@ -367,7 +367,7 @@ pub const Headers = struct {
367 options: std.fmt.FormatOptions,367 options: std.fmt.FormatOptions,
368 context: var,368 context: var,
369 comptime Errors: type,369 comptime Errors: type,
370 output: fn (@typeOf(context), []const u8) Errors!void,370 output: fn (@TypeOf(context), []const u8) Errors!void,
371 ) Errors!void {371 ) Errors!void {
372 var it = self.iterator();372 var it = self.iterator();
373 while (it.next()) |entry| {373 while (it.next()) |entry| {
lib/std/io.zig+4-4
...@@ -663,7 +663,7 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type {...@@ -663,7 +663,7 @@ pub fn BitOutStream(endian: builtin.Endian, comptime Error: type) type {
663 pub fn writeBits(self: *Self, value: var, bits: usize) Error!void {663 pub fn writeBits(self: *Self, value: var, bits: usize) Error!void {
664 if (bits == 0) return;664 if (bits == 0) return;
665665
666 const U = @typeOf(value);666 const U = @TypeOf(value);
667 comptime assert(trait.isUnsignedInt(U));667 comptime assert(trait.isUnsignedInt(U));
668668
669 //by extending the buffer to a minimum of u8 we can cover a number of edge cases669 //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,...@@ -962,7 +962,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
962962
963 /// Deserializes data into the type pointed to by `ptr`963 /// Deserializes data into the type pointed to by `ptr`
964 pub fn deserializeInto(self: *Self, ptr: var) !void {964 pub fn deserializeInto(self: *Self, ptr: var) !void {
965 const T = @typeOf(ptr);965 const T = @TypeOf(ptr);
966 comptime assert(trait.is(builtin.TypeId.Pointer)(T));966 comptime assert(trait.is(builtin.TypeId.Pointer)(T));
967967
968 if (comptime trait.isSlice(T) or comptime trait.isPtrTo(builtin.TypeId.Array)(T)) {968 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...@@ -1091,7 +1091,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
1091 }1091 }
10921092
1093 fn serializeInt(self: *Self, value: var) Error!void {1093 fn serializeInt(self: *Self, value: var) Error!void {
1094 const T = @typeOf(value);1094 const T = @TypeOf(value);
1095 comptime assert(trait.is(builtin.TypeId.Int)(T) or trait.is(builtin.TypeId.Float)(T));1095 comptime assert(trait.is(builtin.TypeId.Int)(T) or trait.is(builtin.TypeId.Float)(T));
10961096
1097 const t_bit_count = comptime meta.bitCount(T);1097 const t_bit_count = comptime meta.bitCount(T);
...@@ -1123,7 +1123,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co...@@ -1123,7 +1123,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
11231123
1124 /// Serializes the passed value into the stream1124 /// Serializes the passed value into the stream
1125 pub fn serialize(self: *Self, value: var) Error!void {1125 pub fn serialize(self: *Self, value: var) Error!void {
1126 const T = comptime @typeOf(value);1126 const T = comptime @TypeOf(value);
11271127
1128 if (comptime trait.isIndexable(T)) {1128 if (comptime trait.isIndexable(T)) {
1129 for (value) |v|1129 for (value) |v|
lib/std/json.zig+3-3
...@@ -1038,7 +1038,7 @@ pub const Value = union(enum) {...@@ -1038,7 +1038,7 @@ pub const Value = union(enum) {
1038 }1038 }
10391039
1040 pub fn dumpStream(self: @This(), stream: var, comptime max_depth: usize) !void {1040 pub fn dumpStream(self: @This(), stream: var, comptime max_depth: usize) !void {
1041 var w = std.json.WriteStream(@typeOf(stream).Child, max_depth).init(stream);1041 var w = std.json.WriteStream(@TypeOf(stream).Child, max_depth).init(stream);
1042 w.newline = "";1042 w.newline = "";
1043 w.one_indent = "";1043 w.one_indent = "";
1044 w.space = "";1044 w.space = "";
...@@ -1048,7 +1048,7 @@ pub const Value = union(enum) {...@@ -1048,7 +1048,7 @@ pub const Value = union(enum) {
1048 pub fn dumpStreamIndent(self: @This(), comptime indent: usize, stream: var, comptime max_depth: usize) !void {1048 pub fn dumpStreamIndent(self: @This(), comptime indent: usize, stream: var, comptime max_depth: usize) !void {
1049 var one_indent = " " ** indent;1049 var one_indent = " " ** indent;
10501050
1051 var w = std.json.WriteStream(@typeOf(stream).Child, max_depth).init(stream);1051 var w = std.json.WriteStream(@TypeOf(stream).Child, max_depth).init(stream);
1052 w.one_indent = one_indent;1052 w.one_indent = one_indent;
1053 try w.emitJson(self);1053 try w.emitJson(self);
1054 }1054 }
...@@ -1338,7 +1338,7 @@ test "write json then parse it" {...@@ -1338,7 +1338,7 @@ test "write json then parse it" {
13381338
1339 var slice_out_stream = std.io.SliceOutStream.init(&out_buffer);1339 var slice_out_stream = std.io.SliceOutStream.init(&out_buffer);
1340 const out_stream = &slice_out_stream.stream;1340 const out_stream = &slice_out_stream.stream;
1341 var jw = WriteStream(@typeOf(out_stream).Child, 4).init(out_stream);1341 var jw = WriteStream(@TypeOf(out_stream).Child, 4).init(out_stream);
13421342
1343 try jw.beginObject();1343 try jw.beginObject();
13441344
lib/std/json/write_stream.zig+2-2
...@@ -155,7 +155,7 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {...@@ -155,7 +155,7 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
155 value: var,155 value: var,
156 ) !void {156 ) !void {
157 assert(self.state[self.state_index] == State.Value);157 assert(self.state[self.state_index] == State.Value);
158 switch (@typeInfo(@typeOf(value))) {158 switch (@typeInfo(@TypeOf(value))) {
159 .Int => |info| {159 .Int => |info| {
160 if (info.bits < 53) {160 if (info.bits < 53) {
161 try self.stream.print("{}", .{value});161 try self.stream.print("{}", .{value});
...@@ -257,7 +257,7 @@ test "json write stream" {...@@ -257,7 +257,7 @@ test "json write stream" {
257 var mem_buf: [1024 * 10]u8 = undefined;257 var mem_buf: [1024 * 10]u8 = undefined;
258 const allocator = &std.heap.FixedBufferAllocator.init(&mem_buf).allocator;258 const allocator = &std.heap.FixedBufferAllocator.init(&mem_buf).allocator;
259259
260 var w = std.json.WriteStream(@typeOf(out).Child, 10).init(out);260 var w = std.json.WriteStream(@TypeOf(out).Child, 10).init(out);
261 try w.emitJson(try getJson(allocator));261 try w.emitJson(try getJson(allocator));
262262
263 const result = slice_stream.getWritten();263 const result = slice_stream.getWritten();
lib/std/math.zig+34-34
...@@ -95,7 +95,7 @@ pub fn approxEq(comptime T: type, x: T, y: T, epsilon: T) bool {...@@ -95,7 +95,7 @@ pub fn approxEq(comptime T: type, x: T, y: T, epsilon: T) bool {
9595
96// TODO: Hide the following in an internal module.96// TODO: Hide the following in an internal module.
97pub fn forceEval(value: var) void {97pub fn forceEval(value: var) void {
98 const T = @typeOf(value);98 const T = @TypeOf(value);
99 switch (T) {99 switch (T) {
100 f16 => {100 f16 => {
101 var x: f16 = undefined;101 var x: f16 = undefined;
...@@ -239,13 +239,13 @@ pub fn Min(comptime A: type, comptime B: type) type {...@@ -239,13 +239,13 @@ pub fn Min(comptime A: type, comptime B: type) type {
239 },239 },
240 else => {},240 else => {},
241 }241 }
242 return @typeOf(@as(A, 0) + @as(B, 0));242 return @TypeOf(@as(A, 0) + @as(B, 0));
243}243}
244244
245/// Returns the smaller number. When one of the parameter's type's full range fits in the other,245/// Returns the smaller number. When one of the parameter's type's full range fits in the other,
246/// the return type is the smaller type.246/// the return type is the smaller type.
247pub fn min(x: var, y: var) Min(@typeOf(x), @typeOf(y)) {247pub fn min(x: var, y: var) Min(@TypeOf(x), @TypeOf(y)) {
248 const Result = Min(@typeOf(x), @typeOf(y));248 const Result = Min(@TypeOf(x), @TypeOf(y));
249 if (x < y) {249 if (x < y) {
250 // TODO Zig should allow this as an implicit cast because x is immutable and in this250 // TODO Zig should allow this as an implicit cast because x is immutable and in this
251 // scope it is known to fit in the return type.251 // scope it is known to fit in the return type.
...@@ -269,33 +269,33 @@ test "math.min" {...@@ -269,33 +269,33 @@ test "math.min" {
269 var a: u16 = 999;269 var a: u16 = 999;
270 var b: u32 = 10;270 var b: u32 = 10;
271 var result = min(a, b);271 var result = min(a, b);
272 testing.expect(@typeOf(result) == u16);272 testing.expect(@TypeOf(result) == u16);
273 testing.expect(result == 10);273 testing.expect(result == 10);
274 }274 }
275 {275 {
276 var a: f64 = 10.34;276 var a: f64 = 10.34;
277 var b: f32 = 999.12;277 var b: f32 = 999.12;
278 var result = min(a, b);278 var result = min(a, b);
279 testing.expect(@typeOf(result) == f64);279 testing.expect(@TypeOf(result) == f64);
280 testing.expect(result == 10.34);280 testing.expect(result == 10.34);
281 }281 }
282 {282 {
283 var a: i8 = -127;283 var a: i8 = -127;
284 var b: i16 = -200;284 var b: i16 = -200;
285 var result = min(a, b);285 var result = min(a, b);
286 testing.expect(@typeOf(result) == i16);286 testing.expect(@TypeOf(result) == i16);
287 testing.expect(result == -200);287 testing.expect(result == -200);
288 }288 }
289 {289 {
290 const a = 10.34;290 const a = 10.34;
291 var b: f32 = 999.12;291 var b: f32 = 999.12;
292 var result = min(a, b);292 var result = min(a, b);
293 testing.expect(@typeOf(result) == f32);293 testing.expect(@TypeOf(result) == f32);
294 testing.expect(result == 10.34);294 testing.expect(result == 10.34);
295 }295 }
296}296}
297297
298pub fn max(x: var, y: var) @typeOf(x + y) {298pub fn max(x: var, y: var) @TypeOf(x + y) {
299 return if (x > y) x else y;299 return if (x > y) x else y;
300}300}
301301
...@@ -318,8 +318,8 @@ pub fn sub(comptime T: type, a: T, b: T) (error{Overflow}!T) {...@@ -318,8 +318,8 @@ pub fn sub(comptime T: type, a: T, b: T) (error{Overflow}!T) {
318 return if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer;318 return if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer;
319}319}
320320
321pub fn negate(x: var) !@typeOf(x) {321pub fn negate(x: var) !@TypeOf(x) {
322 return sub(@typeOf(x), 0, x);322 return sub(@TypeOf(x), 0, x);
323}323}
324324
325pub fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) !T {325pub 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 {...@@ -333,7 +333,7 @@ pub fn shl(comptime T: type, a: T, shift_amt: var) T {
333 const abs_shift_amt = absCast(shift_amt);333 const abs_shift_amt = absCast(shift_amt);
334 const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else @intCast(Log2Int(T), abs_shift_amt);334 const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else @intCast(Log2Int(T), abs_shift_amt);
335335
336 if (@typeOf(shift_amt) == comptime_int or @typeOf(shift_amt).is_signed) {336 if (@TypeOf(shift_amt) == comptime_int or @TypeOf(shift_amt).is_signed) {
337 if (shift_amt < 0) {337 if (shift_amt < 0) {
338 return a >> casted_shift_amt;338 return a >> casted_shift_amt;
339 }339 }
...@@ -359,7 +359,7 @@ pub fn shr(comptime T: type, a: T, shift_amt: var) T {...@@ -359,7 +359,7 @@ pub fn shr(comptime T: type, a: T, shift_amt: var) T {
359 const abs_shift_amt = absCast(shift_amt);359 const abs_shift_amt = absCast(shift_amt);
360 const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else @intCast(Log2Int(T), abs_shift_amt);360 const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else @intCast(Log2Int(T), abs_shift_amt);
361361
362 if (@typeOf(shift_amt) == comptime_int or @typeOf(shift_amt).is_signed) {362 if (@TypeOf(shift_amt) == comptime_int or @TypeOf(shift_amt).is_signed) {
363 if (shift_amt >= 0) {363 if (shift_amt >= 0) {
364 return a >> casted_shift_amt;364 return a >> casted_shift_amt;
365 } else {365 } else {
...@@ -505,12 +505,12 @@ fn testOverflow() void {...@@ -505,12 +505,12 @@ fn testOverflow() void {
505 testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);505 testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000);
506}506}
507507
508pub fn absInt(x: var) !@typeOf(x) {508pub fn absInt(x: var) !@TypeOf(x) {
509 const T = @typeOf(x);509 const T = @TypeOf(x);
510 comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt510 comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt
511 comptime assert(T.is_signed); // must pass a signed integer to absInt511 comptime assert(T.is_signed); // must pass a signed integer to absInt
512512
513 if (x == minInt(@typeOf(x))) {513 if (x == minInt(@TypeOf(x))) {
514 return error.Overflow;514 return error.Overflow;
515 } else {515 } else {
516 @setRuntimeSafety(false);516 @setRuntimeSafety(false);
...@@ -654,16 +654,16 @@ fn testRem() void {...@@ -654,16 +654,16 @@ fn testRem() void {
654/// Returns the absolute value of the integer parameter.654/// Returns the absolute value of the integer parameter.
655/// Result is an unsigned integer.655/// Result is an unsigned integer.
656pub fn absCast(x: var) t: {656pub fn absCast(x: var) t: {
657 if (@typeOf(x) == comptime_int) {657 if (@TypeOf(x) == comptime_int) {
658 break :t comptime_int;658 break :t comptime_int;
659 } else {659 } else {
660 break :t @IntType(false, @typeOf(x).bit_count);660 break :t @IntType(false, @TypeOf(x).bit_count);
661 }661 }
662} {662} {
663 if (@typeOf(x) == comptime_int) {663 if (@TypeOf(x) == comptime_int) {
664 return if (x < 0) -x else x;664 return if (x < 0) -x else x;
665 }665 }
666 const uint = @IntType(false, @typeOf(x).bit_count);666 const uint = @IntType(false, @TypeOf(x).bit_count);
667 if (x >= 0) return @intCast(uint, x);667 if (x >= 0) return @intCast(uint, x);
668668
669 return @intCast(uint, -(x + 1)) + 1;669 return @intCast(uint, -(x + 1)) + 1;
...@@ -671,23 +671,23 @@ pub fn absCast(x: var) t: {...@@ -671,23 +671,23 @@ pub fn absCast(x: var) t: {
671671
672test "math.absCast" {672test "math.absCast" {
673 testing.expect(absCast(@as(i32, -999)) == 999);673 testing.expect(absCast(@as(i32, -999)) == 999);
674 testing.expect(@typeOf(absCast(@as(i32, -999))) == u32);674 testing.expect(@TypeOf(absCast(@as(i32, -999))) == u32);
675675
676 testing.expect(absCast(@as(i32, 999)) == 999);676 testing.expect(absCast(@as(i32, 999)) == 999);
677 testing.expect(@typeOf(absCast(@as(i32, 999))) == u32);677 testing.expect(@TypeOf(absCast(@as(i32, 999))) == u32);
678678
679 testing.expect(absCast(@as(i32, minInt(i32))) == -minInt(i32));679 testing.expect(absCast(@as(i32, minInt(i32))) == -minInt(i32));
680 testing.expect(@typeOf(absCast(@as(i32, minInt(i32)))) == u32);680 testing.expect(@TypeOf(absCast(@as(i32, minInt(i32)))) == u32);
681681
682 testing.expect(absCast(-999) == 999);682 testing.expect(absCast(-999) == 999);
683}683}
684684
685/// Returns the negation of the integer parameter.685/// Returns the negation of the integer parameter.
686/// Result is a signed integer.686/// Result is a signed integer.
687pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) {687pub fn negateCast(x: var) !@IntType(true, @TypeOf(x).bit_count) {
688 if (@typeOf(x).is_signed) return negate(x);688 if (@TypeOf(x).is_signed) return negate(x);
689689
690 const int = @IntType(true, @typeOf(x).bit_count);690 const int = @IntType(true, @TypeOf(x).bit_count);
691 if (x > -minInt(int)) return error.Overflow;691 if (x > -minInt(int)) return error.Overflow;
692692
693 if (x == -minInt(int)) return minInt(int);693 if (x == -minInt(int)) return minInt(int);
...@@ -697,10 +697,10 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) {...@@ -697,10 +697,10 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) {
697697
698test "math.negateCast" {698test "math.negateCast" {
699 testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);699 testing.expect((negateCast(@as(u32, 999)) catch unreachable) == -999);
700 testing.expect(@typeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);700 testing.expect(@TypeOf(negateCast(@as(u32, 999)) catch unreachable) == i32);
701701
702 testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32));702 testing.expect((negateCast(@as(u32, -minInt(i32))) catch unreachable) == minInt(i32));
703 testing.expect(@typeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32);703 testing.expect(@TypeOf(negateCast(@as(u32, -minInt(i32))) catch unreachable) == i32);
704704
705 testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10)));705 testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10)));
706}706}
...@@ -709,10 +709,10 @@ test "math.negateCast" {...@@ -709,10 +709,10 @@ test "math.negateCast" {
709/// return an error.709/// return an error.
710pub fn cast(comptime T: type, x: var) (error{Overflow}!T) {710pub fn cast(comptime T: type, x: var) (error{Overflow}!T) {
711 comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer711 comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer
712 comptime assert(@typeId(@typeOf(x)) == builtin.TypeId.Int); // must pass an integer712 comptime assert(@typeId(@TypeOf(x)) == builtin.TypeId.Int); // must pass an integer
713 if (maxInt(@typeOf(x)) > maxInt(T) and x > maxInt(T)) {713 if (maxInt(@TypeOf(x)) > maxInt(T) and x > maxInt(T)) {
714 return error.Overflow;714 return error.Overflow;
715 } else if (minInt(@typeOf(x)) < minInt(T) and x < minInt(T)) {715 } else if (minInt(@TypeOf(x)) < minInt(T) and x < minInt(T)) {
716 return error.Overflow;716 return error.Overflow;
717 } else {717 } else {
718 return @intCast(T, x);718 return @intCast(T, x);
...@@ -726,13 +726,13 @@ test "math.cast" {...@@ -726,13 +726,13 @@ test "math.cast" {
726 testing.expectError(error.Overflow, cast(u64, @as(i8, -1)));726 testing.expectError(error.Overflow, cast(u64, @as(i8, -1)));
727727
728 testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));728 testing.expect((try cast(u8, @as(u32, 255))) == @as(u8, 255));
729 testing.expect(@typeOf(try cast(u8, @as(u32, 255))) == u8);729 testing.expect(@TypeOf(try cast(u8, @as(u32, 255))) == u8);
730}730}
731731
732pub const AlignCastError = error{UnalignedMemory};732pub const AlignCastError = error{UnalignedMemory};
733733
734/// Align cast a pointer but return an error if it's the wrong alignment734/// Align cast a pointer but return an error if it's the wrong alignment
735pub fn alignCast(comptime alignment: u29, ptr: var) AlignCastError!@typeOf(@alignCast(alignment, ptr)) {735pub fn alignCast(comptime alignment: u29, ptr: var) AlignCastError!@TypeOf(@alignCast(alignment, ptr)) {
736 const addr = @ptrToInt(ptr);736 const addr = @ptrToInt(ptr);
737 if (addr % alignment != 0) {737 if (addr % alignment != 0) {
738 return error.UnalignedMemory;738 return error.UnalignedMemory;
...@@ -858,7 +858,7 @@ test "std.math.log2_int_ceil" {...@@ -858,7 +858,7 @@ test "std.math.log2_int_ceil" {
858}858}
859859
860pub fn lossyCast(comptime T: type, value: var) T {860pub fn lossyCast(comptime T: type, value: var) T {
861 switch (@typeInfo(@typeOf(value))) {861 switch (@typeInfo(@TypeOf(value))) {
862 builtin.TypeId.Int => return @intToFloat(T, value),862 builtin.TypeId.Int => return @intToFloat(T, value),
863 builtin.TypeId.Float => return @floatCast(T, value),863 builtin.TypeId.Float => return @floatCast(T, value),
864 builtin.TypeId.ComptimeInt => return @as(T, value),864 builtin.TypeId.ComptimeInt => return @as(T, value),
lib/std/math/acos.zig+2-2
...@@ -12,8 +12,8 @@ const expect = std.testing.expect;...@@ -12,8 +12,8 @@ const expect = std.testing.expect;
12///12///
13/// Special cases:13/// Special cases:
14/// - acos(x) = nan if x < -1 or x > 114/// - acos(x) = nan if x < -1 or x > 1
15pub fn acos(x: var) @typeOf(x) {15pub fn acos(x: var) @TypeOf(x) {
16 const T = @typeOf(x);16 const T = @TypeOf(x);
17 return switch (T) {17 return switch (T) {
18 f32 => acos32(x),18 f32 => acos32(x),
19 f64 => acos64(x),19 f64 => acos64(x),
lib/std/math/acosh.zig+2-2
...@@ -14,8 +14,8 @@ const expect = std.testing.expect;...@@ -14,8 +14,8 @@ const expect = std.testing.expect;
14/// Special cases:14/// Special cases:
15/// - acosh(x) = snan if x < 115/// - acosh(x) = snan if x < 1
16/// - acosh(nan) = nan16/// - acosh(nan) = nan
17pub fn acosh(x: var) @typeOf(x) {17pub fn acosh(x: var) @TypeOf(x) {
18 const T = @typeOf(x);18 const T = @TypeOf(x);
19 return switch (T) {19 return switch (T) {
20 f32 => acosh32(x),20 f32 => acosh32(x),
21 f64 => acosh64(x),21 f64 => acosh64(x),
lib/std/math/asin.zig+2-2
...@@ -13,8 +13,8 @@ const expect = std.testing.expect;...@@ -13,8 +13,8 @@ const expect = std.testing.expect;
13/// Special Cases:13/// Special Cases:
14/// - asin(+-0) = +-014/// - asin(+-0) = +-0
15/// - asin(x) = nan if x < -1 or x > 115/// - asin(x) = nan if x < -1 or x > 1
16pub fn asin(x: var) @typeOf(x) {16pub fn asin(x: var) @TypeOf(x) {
17 const T = @typeOf(x);17 const T = @TypeOf(x);
18 return switch (T) {18 return switch (T) {
19 f32 => asin32(x),19 f32 => asin32(x),
20 f64 => asin64(x),20 f64 => asin64(x),
lib/std/math/asinh.zig+2-2
...@@ -15,8 +15,8 @@ const maxInt = std.math.maxInt;...@@ -15,8 +15,8 @@ const maxInt = std.math.maxInt;
15/// - asinh(+-0) = +-015/// - asinh(+-0) = +-0
16/// - asinh(+-inf) = +-inf16/// - asinh(+-inf) = +-inf
17/// - asinh(nan) = nan17/// - asinh(nan) = nan
18pub fn asinh(x: var) @typeOf(x) {18pub fn asinh(x: var) @TypeOf(x) {
19 const T = @typeOf(x);19 const T = @TypeOf(x);
20 return switch (T) {20 return switch (T) {
21 f32 => asinh32(x),21 f32 => asinh32(x),
22 f64 => asinh64(x),22 f64 => asinh64(x),
lib/std/math/atan.zig+2-2
...@@ -13,8 +13,8 @@ const expect = std.testing.expect;...@@ -13,8 +13,8 @@ const expect = std.testing.expect;
13/// Special Cases:13/// Special Cases:
14/// - atan(+-0) = +-014/// - atan(+-0) = +-0
15/// - atan(+-inf) = +-pi/215/// - atan(+-inf) = +-pi/2
16pub fn atan(x: var) @typeOf(x) {16pub fn atan(x: var) @TypeOf(x) {
17 const T = @typeOf(x);17 const T = @TypeOf(x);
18 return switch (T) {18 return switch (T) {
19 f32 => atan32(x),19 f32 => atan32(x),
20 f64 => atan64(x),20 f64 => atan64(x),
lib/std/math/atanh.zig+2-2
...@@ -15,8 +15,8 @@ const maxInt = std.math.maxInt;...@@ -15,8 +15,8 @@ const maxInt = std.math.maxInt;
15/// - atanh(+-1) = +-inf with signal15/// - atanh(+-1) = +-inf with signal
16/// - atanh(x) = nan if |x| > 1 with signal16/// - atanh(x) = nan if |x| > 1 with signal
17/// - atanh(nan) = nan17/// - atanh(nan) = nan
18pub fn atanh(x: var) @typeOf(x) {18pub fn atanh(x: var) @TypeOf(x) {
19 const T = @typeOf(x);19 const T = @TypeOf(x);
20 return switch (T) {20 return switch (T) {
21 f32 => atanh_32(x),21 f32 => atanh_32(x),
22 f64 => atanh_64(x),22 f64 => atanh_64(x),
lib/std/math/big/int.zig+2-2
...@@ -268,7 +268,7 @@ pub const Int = struct {...@@ -268,7 +268,7 @@ pub const Int = struct {
268 /// Sets an Int to value. Value must be an primitive integer type.268 /// Sets an Int to value. Value must be an primitive integer type.
269 pub fn set(self: *Int, value: var) Allocator.Error!void {269 pub fn set(self: *Int, value: var) Allocator.Error!void {
270 self.assertWritable();270 self.assertWritable();
271 const T = @typeOf(value);271 const T = @TypeOf(value);
272272
273 switch (@typeInfo(T)) {273 switch (@typeInfo(T)) {
274 TypeId.Int => |info| {274 TypeId.Int => |info| {
...@@ -522,7 +522,7 @@ pub const Int = struct {...@@ -522,7 +522,7 @@ pub const Int = struct {
522 options: std.fmt.FormatOptions,522 options: std.fmt.FormatOptions,
523 context: var,523 context: var,
524 comptime FmtError: type,524 comptime FmtError: type,
525 output: fn (@typeOf(context), []const u8) FmtError!void,525 output: fn (@TypeOf(context), []const u8) FmtError!void,
526 ) FmtError!void {526 ) FmtError!void {
527 self.assertWritable();527 self.assertWritable();
528 // TODO look at fmt and support other bases528 // TODO look at fmt and support other bases
lib/std/math/cbrt.zig+2-2
...@@ -14,8 +14,8 @@ const expect = std.testing.expect;...@@ -14,8 +14,8 @@ const expect = std.testing.expect;
14/// - cbrt(+-0) = +-014/// - cbrt(+-0) = +-0
15/// - cbrt(+-inf) = +-inf15/// - cbrt(+-inf) = +-inf
16/// - cbrt(nan) = nan16/// - cbrt(nan) = nan
17pub fn cbrt(x: var) @typeOf(x) {17pub fn cbrt(x: var) @TypeOf(x) {
18 const T = @typeOf(x);18 const T = @TypeOf(x);
19 return switch (T) {19 return switch (T) {
20 f32 => cbrt32(x),20 f32 => cbrt32(x),
21 f64 => cbrt64(x),21 f64 => cbrt64(x),
lib/std/math/ceil.zig+2-2
...@@ -15,8 +15,8 @@ const expect = std.testing.expect;...@@ -15,8 +15,8 @@ const expect = std.testing.expect;
15/// - ceil(+-0) = +-015/// - ceil(+-0) = +-0
16/// - ceil(+-inf) = +-inf16/// - ceil(+-inf) = +-inf
17/// - ceil(nan) = nan17/// - ceil(nan) = nan
18pub fn ceil(x: var) @typeOf(x) {18pub fn ceil(x: var) @TypeOf(x) {
19 const T = @typeOf(x);19 const T = @TypeOf(x);
20 return switch (T) {20 return switch (T) {
21 f32 => ceil32(x),21 f32 => ceil32(x),
22 f64 => ceil64(x),22 f64 => ceil64(x),
lib/std/math/complex/abs.zig+2-2
...@@ -5,8 +5,8 @@ const cmath = math.complex;...@@ -5,8 +5,8 @@ const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
66
7/// Returns the absolute value (modulus) of z.7/// Returns the absolute value (modulus) of z.
8pub fn abs(z: var) @typeOf(z.re) {8pub fn abs(z: var) @TypeOf(z.re) {
9 const T = @typeOf(z.re);9 const T = @TypeOf(z.re);
10 return math.hypot(T, z.re, z.im);10 return math.hypot(T, z.re, z.im);
11}11}
1212
lib/std/math/complex/acos.zig+2-2
...@@ -5,8 +5,8 @@ const cmath = math.complex;...@@ -5,8 +5,8 @@ const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
66
7/// Returns the arc-cosine of z.7/// Returns the arc-cosine of z.
8pub fn acos(z: var) Complex(@typeOf(z.re)) {8pub fn acos(z: var) Complex(@TypeOf(z.re)) {
9 const T = @typeOf(z.re);9 const T = @TypeOf(z.re);
10 const q = cmath.asin(z);10 const q = cmath.asin(z);
11 return Complex(T).new(@as(T, math.pi) / 2 - q.re, -q.im);11 return Complex(T).new(@as(T, math.pi) / 2 - q.re, -q.im);
12}12}
lib/std/math/complex/acosh.zig+2-2
...@@ -5,8 +5,8 @@ const cmath = math.complex;...@@ -5,8 +5,8 @@ const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
66
7/// Returns the hyperbolic arc-cosine of z.7/// Returns the hyperbolic arc-cosine of z.
8pub fn acosh(z: var) Complex(@typeOf(z.re)) {8pub fn acosh(z: var) Complex(@TypeOf(z.re)) {
9 const T = @typeOf(z.re);9 const T = @TypeOf(z.re);
10 const q = cmath.acos(z);10 const q = cmath.acos(z);
11 return Complex(T).new(-q.im, q.re);11 return Complex(T).new(-q.im, q.re);
12}12}
lib/std/math/complex/arg.zig+2-2
...@@ -5,8 +5,8 @@ const cmath = math.complex;...@@ -5,8 +5,8 @@ const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
66
7/// Returns the angular component (in radians) of z.7/// Returns the angular component (in radians) of z.
8pub fn arg(z: var) @typeOf(z.re) {8pub fn arg(z: var) @TypeOf(z.re) {
9 const T = @typeOf(z.re);9 const T = @TypeOf(z.re);
10 return math.atan2(T, z.im, z.re);10 return math.atan2(T, z.im, z.re);
11}11}
1212
lib/std/math/complex/asin.zig+2-2
...@@ -5,8 +5,8 @@ const cmath = math.complex;...@@ -5,8 +5,8 @@ const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
66
7// Returns the arc-sine of z.7// Returns the arc-sine of z.
8pub fn asin(z: var) Complex(@typeOf(z.re)) {8pub fn asin(z: var) Complex(@TypeOf(z.re)) {
9 const T = @typeOf(z.re);9 const T = @TypeOf(z.re);
10 const x = z.re;10 const x = z.re;
11 const y = z.im;11 const y = z.im;
1212
lib/std/math/complex/asinh.zig+2-2
...@@ -5,8 +5,8 @@ const cmath = math.complex;...@@ -5,8 +5,8 @@ const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
66
7/// Returns the hyperbolic arc-sine of z.7/// Returns the hyperbolic arc-sine of z.
8pub fn asinh(z: var) Complex(@typeOf(z.re)) {8pub fn asinh(z: var) Complex(@TypeOf(z.re)) {
9 const T = @typeOf(z.re);9 const T = @TypeOf(z.re);
10 const q = Complex(T).new(-z.im, z.re);10 const q = Complex(T).new(-z.im, z.re);
11 const r = cmath.asin(q);11 const r = cmath.asin(q);
12 return Complex(T).new(r.im, -r.re);12 return Complex(T).new(r.im, -r.re);
lib/std/math/complex/atan.zig+2-2
...@@ -12,8 +12,8 @@ const cmath = math.complex;...@@ -12,8 +12,8 @@ const cmath = math.complex;
12const Complex = cmath.Complex;12const Complex = cmath.Complex;
1313
14/// Returns the arc-tangent of z.14/// Returns the arc-tangent of z.
15pub fn atan(z: var) @typeOf(z) {15pub fn atan(z: var) @TypeOf(z) {
16 const T = @typeOf(z.re);16 const T = @TypeOf(z.re);
17 return switch (T) {17 return switch (T) {
18 f32 => atan32(z),18 f32 => atan32(z),
19 f64 => atan64(z),19 f64 => atan64(z),
lib/std/math/complex/atanh.zig+2-2
...@@ -5,8 +5,8 @@ const cmath = math.complex;...@@ -5,8 +5,8 @@ const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
66
7/// Returns the hyperbolic arc-tangent of z.7/// Returns the hyperbolic arc-tangent of z.
8pub fn atanh(z: var) Complex(@typeOf(z.re)) {8pub fn atanh(z: var) Complex(@TypeOf(z.re)) {
9 const T = @typeOf(z.re);9 const T = @TypeOf(z.re);
10 const q = Complex(T).new(-z.im, z.re);10 const q = Complex(T).new(-z.im, z.re);
11 const r = cmath.atan(q);11 const r = cmath.atan(q);
12 return Complex(T).new(r.im, -r.re);12 return Complex(T).new(r.im, -r.re);
lib/std/math/complex/conj.zig+2-2
...@@ -5,8 +5,8 @@ const cmath = math.complex;...@@ -5,8 +5,8 @@ const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
66
7/// Returns the complex conjugate of z.7/// Returns the complex conjugate of z.
8pub fn conj(z: var) Complex(@typeOf(z.re)) {8pub fn conj(z: var) Complex(@TypeOf(z.re)) {
9 const T = @typeOf(z.re);9 const T = @TypeOf(z.re);
10 return Complex(T).new(z.re, -z.im);10 return Complex(T).new(z.re, -z.im);
11}11}
1212
lib/std/math/complex/cos.zig+2-2
...@@ -5,8 +5,8 @@ const cmath = math.complex;...@@ -5,8 +5,8 @@ const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
66
7/// Returns the cosine of z.7/// Returns the cosine of z.
8pub fn cos(z: var) Complex(@typeOf(z.re)) {8pub fn cos(z: var) Complex(@TypeOf(z.re)) {
9 const T = @typeOf(z.re);9 const T = @TypeOf(z.re);
10 const p = Complex(T).new(-z.im, z.re);10 const p = Complex(T).new(-z.im, z.re);
11 return cmath.cosh(p);11 return cmath.cosh(p);
12}12}
lib/std/math/complex/cosh.zig+2-2
...@@ -14,8 +14,8 @@ const Complex = cmath.Complex;...@@ -14,8 +14,8 @@ const Complex = cmath.Complex;
14const ldexp_cexp = @import("ldexp.zig").ldexp_cexp;14const ldexp_cexp = @import("ldexp.zig").ldexp_cexp;
1515
16/// Returns the hyperbolic arc-cosine of z.16/// Returns the hyperbolic arc-cosine of z.
17pub fn cosh(z: var) Complex(@typeOf(z.re)) {17pub fn cosh(z: var) Complex(@TypeOf(z.re)) {
18 const T = @typeOf(z.re);18 const T = @TypeOf(z.re);
19 return switch (T) {19 return switch (T) {
20 f32 => cosh32(z),20 f32 => cosh32(z),
21 f64 => cosh64(z),21 f64 => cosh64(z),
lib/std/math/complex/exp.zig+2-2
...@@ -14,8 +14,8 @@ const Complex = cmath.Complex;...@@ -14,8 +14,8 @@ const Complex = cmath.Complex;
14const ldexp_cexp = @import("ldexp.zig").ldexp_cexp;14const ldexp_cexp = @import("ldexp.zig").ldexp_cexp;
1515
16/// Returns e raised to the power of z (e^z).16/// Returns e raised to the power of z (e^z).
17pub fn exp(z: var) @typeOf(z) {17pub fn exp(z: var) @TypeOf(z) {
18 const T = @typeOf(z.re);18 const T = @TypeOf(z.re);
1919
20 return switch (T) {20 return switch (T) {
21 f32 => exp32(z),21 f32 => exp32(z),
lib/std/math/complex/ldexp.zig+2-2
...@@ -11,8 +11,8 @@ const cmath = math.complex;...@@ -11,8 +11,8 @@ const cmath = math.complex;
11const Complex = cmath.Complex;11const Complex = cmath.Complex;
1212
13/// Returns exp(z) scaled to avoid overflow.13/// Returns exp(z) scaled to avoid overflow.
14pub fn ldexp_cexp(z: var, expt: i32) @typeOf(z) {14pub fn ldexp_cexp(z: var, expt: i32) @TypeOf(z) {
15 const T = @typeOf(z.re);15 const T = @TypeOf(z.re);
1616
17 return switch (T) {17 return switch (T) {
18 f32 => ldexp_cexp32(z, expt),18 f32 => ldexp_cexp32(z, expt),
lib/std/math/complex/log.zig+2-2
...@@ -5,8 +5,8 @@ const cmath = math.complex;...@@ -5,8 +5,8 @@ const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
66
7/// Returns the natural logarithm of z.7/// Returns the natural logarithm of z.
8pub fn log(z: var) Complex(@typeOf(z.re)) {8pub fn log(z: var) Complex(@TypeOf(z.re)) {
9 const T = @typeOf(z.re);9 const T = @TypeOf(z.re);
10 const r = cmath.abs(z);10 const r = cmath.abs(z);
11 const phi = cmath.arg(z);11 const phi = cmath.arg(z);
1212
lib/std/math/complex/proj.zig+2-2
...@@ -5,8 +5,8 @@ const cmath = math.complex;...@@ -5,8 +5,8 @@ const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
66
7/// Returns the projection of z onto the riemann sphere.7/// Returns the projection of z onto the riemann sphere.
8pub fn proj(z: var) Complex(@typeOf(z.re)) {8pub fn proj(z: var) Complex(@TypeOf(z.re)) {
9 const T = @typeOf(z.re);9 const T = @TypeOf(z.re);
1010
11 if (math.isInf(z.re) or math.isInf(z.im)) {11 if (math.isInf(z.re) or math.isInf(z.im)) {
12 return Complex(T).new(math.inf(T), math.copysign(T, 0, z.re));12 return Complex(T).new(math.inf(T), math.copysign(T, 0, z.re));
lib/std/math/complex/sin.zig+2-2
...@@ -5,8 +5,8 @@ const cmath = math.complex;...@@ -5,8 +5,8 @@ const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
66
7/// Returns the sine of z.7/// Returns the sine of z.
8pub fn sin(z: var) Complex(@typeOf(z.re)) {8pub fn sin(z: var) Complex(@TypeOf(z.re)) {
9 const T = @typeOf(z.re);9 const T = @TypeOf(z.re);
10 const p = Complex(T).new(-z.im, z.re);10 const p = Complex(T).new(-z.im, z.re);
11 const q = cmath.sinh(p);11 const q = cmath.sinh(p);
12 return Complex(T).new(q.im, -q.re);12 return Complex(T).new(q.im, -q.re);
lib/std/math/complex/sinh.zig+2-2
...@@ -14,8 +14,8 @@ const Complex = cmath.Complex;...@@ -14,8 +14,8 @@ const Complex = cmath.Complex;
14const ldexp_cexp = @import("ldexp.zig").ldexp_cexp;14const ldexp_cexp = @import("ldexp.zig").ldexp_cexp;
1515
16/// Returns the hyperbolic sine of z.16/// Returns the hyperbolic sine of z.
17pub fn sinh(z: var) @typeOf(z) {17pub fn sinh(z: var) @TypeOf(z) {
18 const T = @typeOf(z.re);18 const T = @TypeOf(z.re);
19 return switch (T) {19 return switch (T) {
20 f32 => sinh32(z),20 f32 => sinh32(z),
21 f64 => sinh64(z),21 f64 => sinh64(z),
lib/std/math/complex/sqrt.zig+2-2
...@@ -12,8 +12,8 @@ const Complex = cmath.Complex;...@@ -12,8 +12,8 @@ const Complex = cmath.Complex;
1212
13/// Returns the square root of z. The real and imaginary parts of the result have the same sign13/// Returns the square root of z. The real and imaginary parts of the result have the same sign
14/// as the imaginary part of z.14/// as the imaginary part of z.
15pub fn sqrt(z: var) @typeOf(z) {15pub fn sqrt(z: var) @TypeOf(z) {
16 const T = @typeOf(z.re);16 const T = @TypeOf(z.re);
1717
18 return switch (T) {18 return switch (T) {
19 f32 => sqrt32(z),19 f32 => sqrt32(z),
lib/std/math/complex/tan.zig+2-2
...@@ -5,8 +5,8 @@ const cmath = math.complex;...@@ -5,8 +5,8 @@ const cmath = math.complex;
5const Complex = cmath.Complex;5const Complex = cmath.Complex;
66
7/// Returns the tanget of z.7/// Returns the tanget of z.
8pub fn tan(z: var) Complex(@typeOf(z.re)) {8pub fn tan(z: var) Complex(@TypeOf(z.re)) {
9 const T = @typeOf(z.re);9 const T = @TypeOf(z.re);
10 const q = Complex(T).new(-z.im, z.re);10 const q = Complex(T).new(-z.im, z.re);
11 const r = cmath.tanh(q);11 const r = cmath.tanh(q);
12 return Complex(T).new(r.im, -r.re);12 return Complex(T).new(r.im, -r.re);
lib/std/math/complex/tanh.zig+2-2
...@@ -12,8 +12,8 @@ const cmath = math.complex;...@@ -12,8 +12,8 @@ const cmath = math.complex;
12const Complex = cmath.Complex;12const Complex = cmath.Complex;
1313
14/// Returns the hyperbolic tangent of z.14/// Returns the hyperbolic tangent of z.
15pub fn tanh(z: var) @typeOf(z) {15pub fn tanh(z: var) @TypeOf(z) {
16 const T = @typeOf(z.re);16 const T = @TypeOf(z.re);
17 return switch (T) {17 return switch (T) {
18 f32 => tanh32(z),18 f32 => tanh32(z),
19 f64 => tanh64(z),19 f64 => tanh64(z),
lib/std/math/cos.zig+2-2
...@@ -13,8 +13,8 @@ const expect = std.testing.expect;...@@ -13,8 +13,8 @@ const expect = std.testing.expect;
13/// Special Cases:13/// Special Cases:
14/// - cos(+-inf) = nan14/// - cos(+-inf) = nan
15/// - cos(nan) = nan15/// - cos(nan) = nan
16pub fn cos(x: var) @typeOf(x) {16pub fn cos(x: var) @TypeOf(x) {
17 const T = @typeOf(x);17 const T = @TypeOf(x);
18 return switch (T) {18 return switch (T) {
19 f32 => cos_(f32, x),19 f32 => cos_(f32, x),
20 f64 => cos_(f64, x),20 f64 => cos_(f64, x),
lib/std/math/cosh.zig+2-2
...@@ -17,8 +17,8 @@ const maxInt = std.math.maxInt;...@@ -17,8 +17,8 @@ const maxInt = std.math.maxInt;
17/// - cosh(+-0) = 117/// - cosh(+-0) = 1
18/// - cosh(+-inf) = +inf18/// - cosh(+-inf) = +inf
19/// - cosh(nan) = nan19/// - cosh(nan) = nan
20pub fn cosh(x: var) @typeOf(x) {20pub fn cosh(x: var) @TypeOf(x) {
21 const T = @typeOf(x);21 const T = @TypeOf(x);
22 return switch (T) {22 return switch (T) {
23 f32 => cosh32(x),23 f32 => cosh32(x),
24 f64 => cosh64(x),24 f64 => cosh64(x),
lib/std/math/exp.zig+2-2
...@@ -14,8 +14,8 @@ const builtin = @import("builtin");...@@ -14,8 +14,8 @@ const builtin = @import("builtin");
14/// Special Cases:14/// Special Cases:
15/// - exp(+inf) = +inf15/// - exp(+inf) = +inf
16/// - exp(nan) = nan16/// - exp(nan) = nan
17pub fn exp(x: var) @typeOf(x) {17pub fn exp(x: var) @TypeOf(x) {
18 const T = @typeOf(x);18 const T = @TypeOf(x);
19 return switch (T) {19 return switch (T) {
20 f32 => exp32(x),20 f32 => exp32(x),
21 f64 => exp64(x),21 f64 => exp64(x),
lib/std/math/exp2.zig+2-2
...@@ -13,8 +13,8 @@ const expect = std.testing.expect;...@@ -13,8 +13,8 @@ const expect = std.testing.expect;
13/// Special Cases:13/// Special Cases:
14/// - exp2(+inf) = +inf14/// - exp2(+inf) = +inf
15/// - exp2(nan) = nan15/// - exp2(nan) = nan
16pub fn exp2(x: var) @typeOf(x) {16pub fn exp2(x: var) @TypeOf(x) {
17 const T = @typeOf(x);17 const T = @TypeOf(x);
18 return switch (T) {18 return switch (T) {
19 f32 => exp2_32(x),19 f32 => exp2_32(x),
20 f64 => exp2_64(x),20 f64 => exp2_64(x),
lib/std/math/expm1.zig+2-2
...@@ -18,8 +18,8 @@ const expect = std.testing.expect;...@@ -18,8 +18,8 @@ const expect = std.testing.expect;
18/// - expm1(+inf) = +inf18/// - expm1(+inf) = +inf
19/// - expm1(-inf) = -119/// - expm1(-inf) = -1
20/// - expm1(nan) = nan20/// - expm1(nan) = nan
21pub fn expm1(x: var) @typeOf(x) {21pub fn expm1(x: var) @TypeOf(x) {
22 const T = @typeOf(x);22 const T = @TypeOf(x);
23 return switch (T) {23 return switch (T) {
24 f32 => expm1_32(x),24 f32 => expm1_32(x),
25 f64 => expm1_64(x),25 f64 => expm1_64(x),
lib/std/math/expo2.zig+2-2
...@@ -7,8 +7,8 @@...@@ -7,8 +7,8 @@
7const math = @import("../math.zig");7const math = @import("../math.zig");
88
9/// Returns exp(x) / 2 for x >= log(maxFloat(T)).9/// Returns exp(x) / 2 for x >= log(maxFloat(T)).
10pub fn expo2(x: var) @typeOf(x) {10pub fn expo2(x: var) @TypeOf(x) {
11 const T = @typeOf(x);11 const T = @TypeOf(x);
12 return switch (T) {12 return switch (T) {
13 f32 => expo2f(x),13 f32 => expo2f(x),
14 f64 => expo2d(x),14 f64 => expo2d(x),
lib/std/math/fabs.zig+2-2
...@@ -14,8 +14,8 @@ const maxInt = std.math.maxInt;...@@ -14,8 +14,8 @@ const maxInt = std.math.maxInt;
14/// Special Cases:14/// Special Cases:
15/// - fabs(+-inf) = +inf15/// - fabs(+-inf) = +inf
16/// - fabs(nan) = nan16/// - fabs(nan) = nan
17pub fn fabs(x: var) @typeOf(x) {17pub fn fabs(x: var) @TypeOf(x) {
18 const T = @typeOf(x);18 const T = @TypeOf(x);
19 return switch (T) {19 return switch (T) {
20 f16 => fabs16(x),20 f16 => fabs16(x),
21 f32 => fabs32(x),21 f32 => fabs32(x),
lib/std/math/floor.zig+2-2
...@@ -15,8 +15,8 @@ const math = std.math;...@@ -15,8 +15,8 @@ const math = std.math;
15/// - floor(+-0) = +-015/// - floor(+-0) = +-0
16/// - floor(+-inf) = +-inf16/// - floor(+-inf) = +-inf
17/// - floor(nan) = nan17/// - floor(nan) = nan
18pub fn floor(x: var) @typeOf(x) {18pub fn floor(x: var) @TypeOf(x) {
19 const T = @typeOf(x);19 const T = @TypeOf(x);
20 return switch (T) {20 return switch (T) {
21 f16 => floor16(x),21 f16 => floor16(x),
22 f32 => floor32(x),22 f32 => floor32(x),
lib/std/math/frexp.zig+2-2
...@@ -24,8 +24,8 @@ pub const frexp64_result = frexp_result(f64);...@@ -24,8 +24,8 @@ pub const frexp64_result = frexp_result(f64);
24/// - frexp(+-0) = +-0, 024/// - frexp(+-0) = +-0, 0
25/// - frexp(+-inf) = +-inf, 025/// - frexp(+-inf) = +-inf, 0
26/// - frexp(nan) = nan, undefined26/// - frexp(nan) = nan, undefined
27pub fn frexp(x: var) frexp_result(@typeOf(x)) {27pub fn frexp(x: var) frexp_result(@TypeOf(x)) {
28 const T = @typeOf(x);28 const T = @TypeOf(x);
29 return switch (T) {29 return switch (T) {
30 f32 => frexp32(x),30 f32 => frexp32(x),
31 f64 => frexp64(x),31 f64 => frexp64(x),
lib/std/math/ilogb.zig+1-1
...@@ -17,7 +17,7 @@ const minInt = std.math.minInt;...@@ -17,7 +17,7 @@ const minInt = std.math.minInt;
17/// - ilogb(0) = maxInt(i32)17/// - ilogb(0) = maxInt(i32)
18/// - ilogb(nan) = maxInt(i32)18/// - ilogb(nan) = maxInt(i32)
19pub fn ilogb(x: var) i32 {19pub fn ilogb(x: var) i32 {
20 const T = @typeOf(x);20 const T = @TypeOf(x);
21 return switch (T) {21 return switch (T) {
22 f32 => ilogb32(x),22 f32 => ilogb32(x),
23 f64 => ilogb64(x),23 f64 => ilogb64(x),
lib/std/math/isfinite.zig+1-1
...@@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;...@@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;
55
6/// Returns whether x is a finite value.6/// Returns whether x is a finite value.
7pub fn isFinite(x: var) bool {7pub fn isFinite(x: var) bool {
8 const T = @typeOf(x);8 const T = @TypeOf(x);
9 switch (T) {9 switch (T) {
10 f16 => {10 f16 => {
11 const bits = @bitCast(u16, x);11 const bits = @bitCast(u16, x);
lib/std/math/isinf.zig+3-3
...@@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;...@@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;
55
6/// Returns whether x is an infinity, ignoring sign.6/// Returns whether x is an infinity, ignoring sign.
7pub fn isInf(x: var) bool {7pub fn isInf(x: var) bool {
8 const T = @typeOf(x);8 const T = @TypeOf(x);
9 switch (T) {9 switch (T) {
10 f16 => {10 f16 => {
11 const bits = @bitCast(u16, x);11 const bits = @bitCast(u16, x);
...@@ -31,7 +31,7 @@ pub fn isInf(x: var) bool {...@@ -31,7 +31,7 @@ pub fn isInf(x: var) bool {
3131
32/// Returns whether x is an infinity with a positive sign.32/// Returns whether x is an infinity with a positive sign.
33pub fn isPositiveInf(x: var) bool {33pub fn isPositiveInf(x: var) bool {
34 const T = @typeOf(x);34 const T = @TypeOf(x);
35 switch (T) {35 switch (T) {
36 f16 => {36 f16 => {
37 return @bitCast(u16, x) == 0x7C00;37 return @bitCast(u16, x) == 0x7C00;
...@@ -53,7 +53,7 @@ pub fn isPositiveInf(x: var) bool {...@@ -53,7 +53,7 @@ pub fn isPositiveInf(x: var) bool {
5353
54/// Returns whether x is an infinity with a negative sign.54/// Returns whether x is an infinity with a negative sign.
55pub fn isNegativeInf(x: var) bool {55pub fn isNegativeInf(x: var) bool {
56 const T = @typeOf(x);56 const T = @TypeOf(x);
57 switch (T) {57 switch (T) {
58 f16 => {58 f16 => {
59 return @bitCast(u16, x) == 0xFC00;59 return @bitCast(u16, x) == 0xFC00;
lib/std/math/isnormal.zig+1-1
...@@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;...@@ -5,7 +5,7 @@ const maxInt = std.math.maxInt;
55
6// Returns whether x has a normalized representation (i.e. integer part of mantissa is 1).6// Returns whether x has a normalized representation (i.e. integer part of mantissa is 1).
7pub fn isNormal(x: var) bool {7pub fn isNormal(x: var) bool {
8 const T = @typeOf(x);8 const T = @TypeOf(x);
9 switch (T) {9 switch (T) {
10 f16 => {10 f16 => {
11 const bits = @bitCast(u16, x);11 const bits = @bitCast(u16, x);
lib/std/math/ln.zig+4-4
...@@ -17,11 +17,11 @@ const TypeId = builtin.TypeId;...@@ -17,11 +17,11 @@ const TypeId = builtin.TypeId;
17/// - ln(0) = -inf17/// - ln(0) = -inf
18/// - ln(x) = nan if x < 018/// - ln(x) = nan if x < 0
19/// - ln(nan) = nan19/// - ln(nan) = nan
20pub fn ln(x: var) @typeOf(x) {20pub fn ln(x: var) @TypeOf(x) {
21 const T = @typeOf(x);21 const T = @TypeOf(x);
22 switch (@typeId(T)) {22 switch (@typeId(T)) {
23 TypeId.ComptimeFloat => {23 TypeId.ComptimeFloat => {
24 return @typeOf(1.0)(ln_64(x));24 return @TypeOf(1.0)(ln_64(x));
25 },25 },
26 TypeId.Float => {26 TypeId.Float => {
27 return switch (T) {27 return switch (T) {
...@@ -31,7 +31,7 @@ pub fn ln(x: var) @typeOf(x) {...@@ -31,7 +31,7 @@ pub fn ln(x: var) @typeOf(x) {
31 };31 };
32 },32 },
33 TypeId.ComptimeInt => {33 TypeId.ComptimeInt => {
34 return @typeOf(1)(math.floor(ln_64(@as(f64, x))));34 return @TypeOf(1)(math.floor(ln_64(@as(f64, x))));
35 },35 },
36 TypeId.Int => {36 TypeId.Int => {
37 return @as(T, math.floor(ln_64(@as(f64, x))));37 return @as(T, math.floor(ln_64(@as(f64, x))));
lib/std/math/log.zig+2-2
...@@ -23,10 +23,10 @@ pub fn log(comptime T: type, base: T, x: T) T {...@@ -23,10 +23,10 @@ pub fn log(comptime T: type, base: T, x: T) T {
23 const float_base = math.lossyCast(f64, base);23 const float_base = math.lossyCast(f64, base);
24 switch (@typeId(T)) {24 switch (@typeId(T)) {
25 TypeId.ComptimeFloat => {25 TypeId.ComptimeFloat => {
26 return @typeOf(1.0)(math.ln(@as(f64, x)) / math.ln(float_base));26 return @TypeOf(1.0)(math.ln(@as(f64, x)) / math.ln(float_base));
27 },27 },
28 TypeId.ComptimeInt => {28 TypeId.ComptimeInt => {
29 return @typeOf(1)(math.floor(math.ln(@as(f64, x)) / math.ln(float_base)));29 return @TypeOf(1)(math.floor(math.ln(@as(f64, x)) / math.ln(float_base)));
30 },30 },
31 builtin.TypeId.Int => {31 builtin.TypeId.Int => {
32 // TODO implement integer log without using float math32 // TODO implement integer log without using float math
lib/std/math/log10.zig+4-4
...@@ -18,11 +18,11 @@ const maxInt = std.math.maxInt;...@@ -18,11 +18,11 @@ const maxInt = std.math.maxInt;
18/// - log10(0) = -inf18/// - log10(0) = -inf
19/// - log10(x) = nan if x < 019/// - log10(x) = nan if x < 0
20/// - log10(nan) = nan20/// - log10(nan) = nan
21pub fn log10(x: var) @typeOf(x) {21pub fn log10(x: var) @TypeOf(x) {
22 const T = @typeOf(x);22 const T = @TypeOf(x);
23 switch (@typeId(T)) {23 switch (@typeId(T)) {
24 TypeId.ComptimeFloat => {24 TypeId.ComptimeFloat => {
25 return @typeOf(1.0)(log10_64(x));25 return @TypeOf(1.0)(log10_64(x));
26 },26 },
27 TypeId.Float => {27 TypeId.Float => {
28 return switch (T) {28 return switch (T) {
...@@ -32,7 +32,7 @@ pub fn log10(x: var) @typeOf(x) {...@@ -32,7 +32,7 @@ pub fn log10(x: var) @typeOf(x) {
32 };32 };
33 },33 },
34 TypeId.ComptimeInt => {34 TypeId.ComptimeInt => {
35 return @typeOf(1)(math.floor(log10_64(@as(f64, x))));35 return @TypeOf(1)(math.floor(log10_64(@as(f64, x))));
36 },36 },
37 TypeId.Int => {37 TypeId.Int => {
38 return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x))));38 return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x))));
lib/std/math/log1p.zig+2-2
...@@ -17,8 +17,8 @@ const expect = std.testing.expect;...@@ -17,8 +17,8 @@ const expect = std.testing.expect;
17/// - log1p(-1) = -inf17/// - log1p(-1) = -inf
18/// - log1p(x) = nan if x < -118/// - log1p(x) = nan if x < -1
19/// - log1p(nan) = nan19/// - log1p(nan) = nan
20pub fn log1p(x: var) @typeOf(x) {20pub fn log1p(x: var) @TypeOf(x) {
21 const T = @typeOf(x);21 const T = @TypeOf(x);
22 return switch (T) {22 return switch (T) {
23 f32 => log1p_32(x),23 f32 => log1p_32(x),
24 f64 => log1p_64(x),24 f64 => log1p_64(x),
lib/std/math/log2.zig+3-3
...@@ -18,11 +18,11 @@ const maxInt = std.math.maxInt;...@@ -18,11 +18,11 @@ const maxInt = std.math.maxInt;
18/// - log2(0) = -inf18/// - log2(0) = -inf
19/// - log2(x) = nan if x < 019/// - log2(x) = nan if x < 0
20/// - log2(nan) = nan20/// - log2(nan) = nan
21pub fn log2(x: var) @typeOf(x) {21pub fn log2(x: var) @TypeOf(x) {
22 const T = @typeOf(x);22 const T = @TypeOf(x);
23 switch (@typeId(T)) {23 switch (@typeId(T)) {
24 TypeId.ComptimeFloat => {24 TypeId.ComptimeFloat => {
25 return @typeOf(1.0)(log2_64(x));25 return @TypeOf(1.0)(log2_64(x));
26 },26 },
27 TypeId.Float => {27 TypeId.Float => {
28 return switch (T) {28 return switch (T) {
lib/std/math/modf.zig+2-2
...@@ -24,8 +24,8 @@ pub const modf64_result = modf_result(f64);...@@ -24,8 +24,8 @@ pub const modf64_result = modf_result(f64);
24/// Special Cases:24/// Special Cases:
25/// - modf(+-inf) = +-inf, nan25/// - modf(+-inf) = +-inf, nan
26/// - modf(nan) = nan, nan26/// - modf(nan) = nan, nan
27pub fn modf(x: var) modf_result(@typeOf(x)) {27pub fn modf(x: var) modf_result(@TypeOf(x)) {
28 const T = @typeOf(x);28 const T = @TypeOf(x);
29 return switch (T) {29 return switch (T) {
30 f32 => modf32(x),30 f32 => modf32(x),
31 f64 => modf64(x),31 f64 => modf64(x),
lib/std/math/round.zig+2-2
...@@ -15,8 +15,8 @@ const math = std.math;...@@ -15,8 +15,8 @@ const math = std.math;
15/// - round(+-0) = +-015/// - round(+-0) = +-0
16/// - round(+-inf) = +-inf16/// - round(+-inf) = +-inf
17/// - round(nan) = nan17/// - round(nan) = nan
18pub fn round(x: var) @typeOf(x) {18pub fn round(x: var) @TypeOf(x) {
19 const T = @typeOf(x);19 const T = @TypeOf(x);
20 return switch (T) {20 return switch (T) {
21 f32 => round32(x),21 f32 => round32(x),
22 f64 => round64(x),22 f64 => round64(x),
lib/std/math/scalbn.zig+2-2
...@@ -9,8 +9,8 @@ const math = std.math;...@@ -9,8 +9,8 @@ const math = std.math;
9const expect = std.testing.expect;9const expect = std.testing.expect;
1010
11/// Returns x * 2^n.11/// Returns x * 2^n.
12pub fn scalbn(x: var, n: i32) @typeOf(x) {12pub fn scalbn(x: var, n: i32) @TypeOf(x) {
13 const T = @typeOf(x);13 const T = @TypeOf(x);
14 return switch (T) {14 return switch (T) {
15 f32 => scalbn32(x, n),15 f32 => scalbn32(x, n),
16 f64 => scalbn64(x, n),16 f64 => scalbn64(x, n),
lib/std/math/signbit.zig+1-1
...@@ -4,7 +4,7 @@ const expect = std.testing.expect;...@@ -4,7 +4,7 @@ const expect = std.testing.expect;
44
5/// Returns whether x is negative or negative 0.5/// Returns whether x is negative or negative 0.
6pub fn signbit(x: var) bool {6pub fn signbit(x: var) bool {
7 const T = @typeOf(x);7 const T = @TypeOf(x);
8 return switch (T) {8 return switch (T) {
9 f16 => signbit16(x),9 f16 => signbit16(x),
10 f32 => signbit32(x),10 f32 => signbit32(x),
lib/std/math/sin.zig+2-2
...@@ -14,8 +14,8 @@ const expect = std.testing.expect;...@@ -14,8 +14,8 @@ const expect = std.testing.expect;
14/// - sin(+-0) = +-014/// - sin(+-0) = +-0
15/// - sin(+-inf) = nan15/// - sin(+-inf) = nan
16/// - sin(nan) = nan16/// - sin(nan) = nan
17pub fn sin(x: var) @typeOf(x) {17pub fn sin(x: var) @TypeOf(x) {
18 const T = @typeOf(x);18 const T = @TypeOf(x);
19 return switch (T) {19 return switch (T) {
20 f32 => sin_(T, x),20 f32 => sin_(T, x),
21 f64 => sin_(T, x),21 f64 => sin_(T, x),
lib/std/math/sinh.zig+2-2
...@@ -17,8 +17,8 @@ const maxInt = std.math.maxInt;...@@ -17,8 +17,8 @@ const maxInt = std.math.maxInt;
17/// - sinh(+-0) = +-017/// - sinh(+-0) = +-0
18/// - sinh(+-inf) = +-inf18/// - sinh(+-inf) = +-inf
19/// - sinh(nan) = nan19/// - sinh(nan) = nan
20pub fn sinh(x: var) @typeOf(x) {20pub fn sinh(x: var) @TypeOf(x) {
21 const T = @typeOf(x);21 const T = @TypeOf(x);
22 return switch (T) {22 return switch (T) {
23 f32 => sinh32(x),23 f32 => sinh32(x),
24 f64 => sinh64(x),24 f64 => sinh64(x),
lib/std/math/sqrt.zig+2-2
...@@ -12,8 +12,8 @@ const maxInt = std.math.maxInt;...@@ -12,8 +12,8 @@ const maxInt = std.math.maxInt;
12/// - sqrt(+-0) = +-012/// - sqrt(+-0) = +-0
13/// - sqrt(x) = nan if x < 013/// - sqrt(x) = nan if x < 0
14/// - sqrt(nan) = nan14/// - sqrt(nan) = nan
15pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typeOf(x).bit_count / 2) else @typeOf(x)) {15pub fn sqrt(x: var) (if (@typeId(@TypeOf(x)) == TypeId.Int) @IntType(false, @TypeOf(x).bit_count / 2) else @TypeOf(x)) {
16 const T = @typeOf(x);16 const T = @TypeOf(x);
17 switch (@typeId(T)) {17 switch (@typeId(T)) {
18 TypeId.ComptimeFloat => return @as(T, @sqrt(f64, x)), // TODO upgrade to f12818 TypeId.ComptimeFloat => return @as(T, @sqrt(f64, x)), // TODO upgrade to f128
19 TypeId.Float => return @sqrt(T, x),19 TypeId.Float => return @sqrt(T, x),
lib/std/math/tan.zig+2-2
...@@ -14,8 +14,8 @@ const expect = std.testing.expect;...@@ -14,8 +14,8 @@ const expect = std.testing.expect;
14/// - tan(+-0) = +-014/// - tan(+-0) = +-0
15/// - tan(+-inf) = nan15/// - tan(+-inf) = nan
16/// - tan(nan) = nan16/// - tan(nan) = nan
17pub fn tan(x: var) @typeOf(x) {17pub fn tan(x: var) @TypeOf(x) {
18 const T = @typeOf(x);18 const T = @TypeOf(x);
19 return switch (T) {19 return switch (T) {
20 f32 => tan_(f32, x),20 f32 => tan_(f32, x),
21 f64 => tan_(f64, x),21 f64 => tan_(f64, x),
lib/std/math/tanh.zig+2-2
...@@ -17,8 +17,8 @@ const maxInt = std.math.maxInt;...@@ -17,8 +17,8 @@ const maxInt = std.math.maxInt;
17/// - sinh(+-0) = +-017/// - sinh(+-0) = +-0
18/// - sinh(+-inf) = +-118/// - sinh(+-inf) = +-1
19/// - sinh(nan) = nan19/// - sinh(nan) = nan
20pub fn tanh(x: var) @typeOf(x) {20pub fn tanh(x: var) @TypeOf(x) {
21 const T = @typeOf(x);21 const T = @TypeOf(x);
22 return switch (T) {22 return switch (T) {
23 f32 => tanh32(x),23 f32 => tanh32(x),
24 f64 => tanh64(x),24 f64 => tanh64(x),
lib/std/math/trunc.zig+2-2
...@@ -15,8 +15,8 @@ const maxInt = std.math.maxInt;...@@ -15,8 +15,8 @@ const maxInt = std.math.maxInt;
15/// - trunc(+-0) = +-015/// - trunc(+-0) = +-0
16/// - trunc(+-inf) = +-inf16/// - trunc(+-inf) = +-inf
17/// - trunc(nan) = nan17/// - trunc(nan) = nan
18pub fn trunc(x: var) @typeOf(x) {18pub fn trunc(x: var) @TypeOf(x) {
19 const T = @typeOf(x);19 const T = @TypeOf(x);
20 return switch (T) {20 return switch (T) {
21 f32 => trunc32(x),21 f32 => trunc32(x),
22 f64 => trunc64(x),22 f64 => trunc64(x),
lib/std/mem.zig+18-18
...@@ -86,7 +86,7 @@ pub const Allocator = struct {...@@ -86,7 +86,7 @@ pub const Allocator = struct {
86 /// `ptr` should be the return value of `create`, or otherwise86 /// `ptr` should be the return value of `create`, or otherwise
87 /// have the same address and alignment property.87 /// have the same address and alignment property.
88 pub fn destroy(self: *Allocator, ptr: var) void {88 pub fn destroy(self: *Allocator, ptr: var) void {
89 const T = @typeOf(ptr).Child;89 const T = @TypeOf(ptr).Child;
90 if (@sizeOf(T) == 0) return;90 if (@sizeOf(T) == 0) return;
91 const non_const_ptr = @intToPtr([*]u8, @ptrToInt(ptr));91 const non_const_ptr = @intToPtr([*]u8, @ptrToInt(ptr));
92 const shrink_result = self.shrinkFn(self, non_const_ptr[0..@sizeOf(T)], @alignOf(T), 0, 1);92 const shrink_result = self.shrinkFn(self, non_const_ptr[0..@sizeOf(T)], @alignOf(T), 0, 1);
...@@ -147,10 +147,10 @@ pub const Allocator = struct {...@@ -147,10 +147,10 @@ pub const Allocator = struct {
147 /// If you need guaranteed success, call `shrink`.147 /// If you need guaranteed success, call `shrink`.
148 /// If `new_n` is 0, this is the same as `free` and it always succeeds.148 /// If `new_n` is 0, this is the same as `free` and it always succeeds.
149 pub fn realloc(self: *Allocator, old_mem: var, new_n: usize) t: {149 pub fn realloc(self: *Allocator, old_mem: var, new_n: usize) t: {
150 const Slice = @typeInfo(@typeOf(old_mem)).Pointer;150 const Slice = @typeInfo(@TypeOf(old_mem)).Pointer;
151 break :t Error![]align(Slice.alignment) Slice.child;151 break :t Error![]align(Slice.alignment) Slice.child;
152 } {152 } {
153 const old_alignment = @typeInfo(@typeOf(old_mem)).Pointer.alignment;153 const old_alignment = @typeInfo(@TypeOf(old_mem)).Pointer.alignment;
154 return self.alignedRealloc(old_mem, old_alignment, new_n);154 return self.alignedRealloc(old_mem, old_alignment, new_n);
155 }155 }
156156
...@@ -162,8 +162,8 @@ pub const Allocator = struct {...@@ -162,8 +162,8 @@ pub const Allocator = struct {
162 old_mem: var,162 old_mem: var,
163 comptime new_alignment: u29,163 comptime new_alignment: u29,
164 new_n: usize,164 new_n: usize,
165 ) Error![]align(new_alignment) @typeInfo(@typeOf(old_mem)).Pointer.child {165 ) Error![]align(new_alignment) @typeInfo(@TypeOf(old_mem)).Pointer.child {
166 const Slice = @typeInfo(@typeOf(old_mem)).Pointer;166 const Slice = @typeInfo(@TypeOf(old_mem)).Pointer;
167 const T = Slice.child;167 const T = Slice.child;
168 if (old_mem.len == 0) {168 if (old_mem.len == 0) {
169 return self.alignedAlloc(T, new_alignment, new_n);169 return self.alignedAlloc(T, new_alignment, new_n);
...@@ -189,10 +189,10 @@ pub const Allocator = struct {...@@ -189,10 +189,10 @@ pub const Allocator = struct {
189 /// Returned slice has same alignment as old_mem.189 /// Returned slice has same alignment as old_mem.
190 /// Shrinking to 0 is the same as calling `free`.190 /// Shrinking to 0 is the same as calling `free`.
191 pub fn shrink(self: *Allocator, old_mem: var, new_n: usize) t: {191 pub fn shrink(self: *Allocator, old_mem: var, new_n: usize) t: {
192 const Slice = @typeInfo(@typeOf(old_mem)).Pointer;192 const Slice = @typeInfo(@TypeOf(old_mem)).Pointer;
193 break :t []align(Slice.alignment) Slice.child;193 break :t []align(Slice.alignment) Slice.child;
194 } {194 } {
195 const old_alignment = @typeInfo(@typeOf(old_mem)).Pointer.alignment;195 const old_alignment = @typeInfo(@TypeOf(old_mem)).Pointer.alignment;
196 return self.alignedShrink(old_mem, old_alignment, new_n);196 return self.alignedShrink(old_mem, old_alignment, new_n);
197 }197 }
198198
...@@ -204,8 +204,8 @@ pub const Allocator = struct {...@@ -204,8 +204,8 @@ pub const Allocator = struct {
204 old_mem: var,204 old_mem: var,
205 comptime new_alignment: u29,205 comptime new_alignment: u29,
206 new_n: usize,206 new_n: usize,
207 ) []align(new_alignment) @typeInfo(@typeOf(old_mem)).Pointer.child {207 ) []align(new_alignment) @typeInfo(@TypeOf(old_mem)).Pointer.child {
208 const Slice = @typeInfo(@typeOf(old_mem)).Pointer;208 const Slice = @typeInfo(@TypeOf(old_mem)).Pointer;
209 const T = Slice.child;209 const T = Slice.child;
210210
211 if (new_n == 0) {211 if (new_n == 0) {
...@@ -229,7 +229,7 @@ pub const Allocator = struct {...@@ -229,7 +229,7 @@ pub const Allocator = struct {
229 /// Free an array allocated with `alloc`. To free a single item,229 /// Free an array allocated with `alloc`. To free a single item,
230 /// see `destroy`.230 /// see `destroy`.
231 pub fn free(self: *Allocator, memory: var) void {231 pub fn free(self: *Allocator, memory: var) void {
232 const Slice = @typeInfo(@typeOf(memory)).Pointer;232 const Slice = @typeInfo(@TypeOf(memory)).Pointer;
233 const bytes = @sliceToBytes(memory);233 const bytes = @sliceToBytes(memory);
234 if (bytes.len == 0) return;234 if (bytes.len == 0) return;
235 const non_const_ptr = @intToPtr([*]u8, @ptrToInt(bytes.ptr));235 const non_const_ptr = @intToPtr([*]u8, @ptrToInt(bytes.ptr));
...@@ -1323,8 +1323,8 @@ fn AsBytesReturnType(comptime P: type) type {...@@ -1323,8 +1323,8 @@ fn AsBytesReturnType(comptime P: type) type {
1323}1323}
13241324
1325///Given a pointer to a single item, returns a slice of the underlying bytes, preserving constness.1325///Given a pointer to a single item, returns a slice of the underlying bytes, preserving constness.
1326pub fn asBytes(ptr: var) AsBytesReturnType(@typeOf(ptr)) {1326pub fn asBytes(ptr: var) AsBytesReturnType(@TypeOf(ptr)) {
1327 const P = @typeOf(ptr);1327 const P = @TypeOf(ptr);
1328 return @ptrCast(AsBytesReturnType(P), ptr);1328 return @ptrCast(AsBytesReturnType(P), ptr);
1329}1329}
13301330
...@@ -1363,7 +1363,7 @@ test "asBytes" {...@@ -1363,7 +1363,7 @@ test "asBytes" {
1363}1363}
13641364
1365///Given any value, returns a copy of its bytes in an array.1365///Given any value, returns a copy of its bytes in an array.
1366pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 {1366pub fn toBytes(value: var) [@sizeOf(@TypeOf(value))]u8 {
1367 return asBytes(&value).*;1367 return asBytes(&value).*;
1368}1368}
13691369
...@@ -1397,8 +1397,8 @@ fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {...@@ -1397,8 +1397,8 @@ fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {
13971397
1398///Given a pointer to an array of bytes, returns a pointer to a value of the specified type1398///Given a pointer to an array of bytes, returns a pointer to a value of the specified type
1399/// backed by those bytes, preserving constness.1399/// backed by those bytes, preserving constness.
1400pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @typeOf(bytes)) {1400pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @TypeOf(bytes)) {
1401 return @ptrCast(BytesAsValueReturnType(T, @typeOf(bytes)), bytes);1401 return @ptrCast(BytesAsValueReturnType(T, @TypeOf(bytes)), bytes);
1402}1402}
14031403
1404test "bytesAsValue" {1404test "bytesAsValue" {
...@@ -1460,11 +1460,11 @@ fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type {...@@ -1460,11 +1460,11 @@ fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type {
1460}1460}
14611461
1462///Given a pointer to an array, returns a pointer to a portion of that array, preserving constness.1462///Given a pointer to an array, returns a pointer to a portion of that array, preserving constness.
1463pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubArrayPtrReturnType(@typeOf(ptr), length) {1463pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubArrayPtrReturnType(@TypeOf(ptr), length) {
1464 assert(start + length <= ptr.*.len);1464 assert(start + length <= ptr.*.len);
14651465
1466 const ReturnType = SubArrayPtrReturnType(@typeOf(ptr), length);1466 const ReturnType = SubArrayPtrReturnType(@TypeOf(ptr), length);
1467 const T = meta.Child(meta.Child(@typeOf(ptr)));1467 const T = meta.Child(meta.Child(@TypeOf(ptr)));
1468 return @ptrCast(ReturnType, &ptr[start]);1468 return @ptrCast(ReturnType, &ptr[start]);
1469}1469}
14701470
lib/std/meta.zig+7-7
...@@ -11,7 +11,7 @@ const TypeId = builtin.TypeId;...@@ -11,7 +11,7 @@ const TypeId = builtin.TypeId;
11const TypeInfo = builtin.TypeInfo;11const TypeInfo = builtin.TypeInfo;
1212
13pub fn tagName(v: var) []const u8 {13pub fn tagName(v: var) []const u8 {
14 const T = @typeOf(v);14 const T = @TypeOf(v);
15 switch (@typeInfo(T)) {15 switch (@typeInfo(T)) {
16 TypeId.ErrorSet => return @errorName(v),16 TypeId.ErrorSet => return @errorName(v),
17 else => return @tagName(v),17 else => return @tagName(v),
...@@ -339,8 +339,8 @@ test "std.meta.TagType" {...@@ -339,8 +339,8 @@ test "std.meta.TagType" {
339}339}
340340
341///Returns the active tag of a tagged union341///Returns the active tag of a tagged union
342pub fn activeTag(u: var) @TagType(@typeOf(u)) {342pub fn activeTag(u: var) @TagType(@TypeOf(u)) {
343 const T = @typeOf(u);343 const T = @TypeOf(u);
344 return @as(@TagType(T), u);344 return @as(@TagType(T), u);
345}345}
346346
...@@ -365,7 +365,7 @@ test "std.meta.activeTag" {...@@ -365,7 +365,7 @@ test "std.meta.activeTag" {
365///Given a tagged union type, and an enum, return the type of the union365///Given a tagged union type, and an enum, return the type of the union
366/// field corresponding to the enum tag.366/// field corresponding to the enum tag.
367pub fn TagPayloadType(comptime U: type, tag: var) type {367pub fn TagPayloadType(comptime U: type, tag: var) type {
368 const Tag = @typeOf(tag);368 const Tag = @TypeOf(tag);
369 testing.expect(trait.is(builtin.TypeId.Union)(U));369 testing.expect(trait.is(builtin.TypeId.Union)(U));
370 testing.expect(trait.is(builtin.TypeId.Enum)(Tag));370 testing.expect(trait.is(builtin.TypeId.Enum)(Tag));
371371
...@@ -386,13 +386,13 @@ test "std.meta.TagPayloadType" {...@@ -386,13 +386,13 @@ test "std.meta.TagPayloadType" {
386 };386 };
387 const MovedEvent = TagPayloadType(Event, Event.Moved);387 const MovedEvent = TagPayloadType(Event, Event.Moved);
388 var e: Event = undefined;388 var e: Event = undefined;
389 testing.expect(MovedEvent == @typeOf(e.Moved));389 testing.expect(MovedEvent == @TypeOf(e.Moved));
390}390}
391391
392///Compares two of any type for equality. Containers are compared on a field-by-field basis,392///Compares two of any type for equality. Containers are compared on a field-by-field basis,
393/// where possible. Pointers are not followed.393/// where possible. Pointers are not followed.
394pub fn eql(a: var, b: @typeOf(a)) bool {394pub fn eql(a: var, b: @TypeOf(a)) bool {
395 const T = @typeOf(a);395 const T = @TypeOf(a);
396396
397 switch (@typeId(T)) {397 switch (@typeId(T)) {
398 builtin.TypeId.Struct => {398 builtin.TypeId.Struct => {
lib/std/meta/trait.zig+21-21
...@@ -13,7 +13,7 @@ fn traitFnWorkaround(comptime T: type) bool {...@@ -13,7 +13,7 @@ fn traitFnWorkaround(comptime T: type) bool {
13 return false;13 return false;
14}14}
1515
16pub const TraitFn = @typeOf(traitFnWorkaround);16pub const TraitFn = @TypeOf(traitFnWorkaround);
17///17///
1818
19//////Trait generators19//////Trait generators
...@@ -61,7 +61,7 @@ pub fn hasFn(comptime name: []const u8) TraitFn {...@@ -61,7 +61,7 @@ pub fn hasFn(comptime name: []const u8) TraitFn {
61 pub fn trait(comptime T: type) bool {61 pub fn trait(comptime T: type) bool {
62 if (!comptime isContainer(T)) return false;62 if (!comptime isContainer(T)) return false;
63 if (!comptime @hasDecl(T, name)) return false;63 if (!comptime @hasDecl(T, name)) return false;
64 const DeclType = @typeOf(@field(T, name));64 const DeclType = @TypeOf(@field(T, name));
65 const decl_type_id = @typeId(DeclType);65 const decl_type_id = @typeId(DeclType);
66 return decl_type_id == builtin.TypeId.Fn;66 return decl_type_id == builtin.TypeId.Fn;
67 }67 }
...@@ -236,9 +236,9 @@ pub fn isSingleItemPtr(comptime T: type) bool {...@@ -236,9 +236,9 @@ pub fn isSingleItemPtr(comptime T: type) bool {
236236
237test "std.meta.trait.isSingleItemPtr" {237test "std.meta.trait.isSingleItemPtr" {
238 const array = [_]u8{0} ** 10;238 const array = [_]u8{0} ** 10;
239 testing.expect(isSingleItemPtr(@typeOf(&array[0])));239 testing.expect(isSingleItemPtr(@TypeOf(&array[0])));
240 testing.expect(!isSingleItemPtr(@typeOf(array)));240 testing.expect(!isSingleItemPtr(@TypeOf(array)));
241 testing.expect(!isSingleItemPtr(@typeOf(array[0..1])));241 testing.expect(!isSingleItemPtr(@TypeOf(array[0..1])));
242}242}
243243
244///244///
...@@ -253,9 +253,9 @@ pub fn isManyItemPtr(comptime T: type) bool {...@@ -253,9 +253,9 @@ pub fn isManyItemPtr(comptime T: type) bool {
253test "std.meta.trait.isManyItemPtr" {253test "std.meta.trait.isManyItemPtr" {
254 const array = [_]u8{0} ** 10;254 const array = [_]u8{0} ** 10;
255 const mip = @ptrCast([*]const u8, &array[0]);255 const mip = @ptrCast([*]const u8, &array[0]);
256 testing.expect(isManyItemPtr(@typeOf(mip)));256 testing.expect(isManyItemPtr(@TypeOf(mip)));
257 testing.expect(!isManyItemPtr(@typeOf(array)));257 testing.expect(!isManyItemPtr(@TypeOf(array)));
258 testing.expect(!isManyItemPtr(@typeOf(array[0..1])));258 testing.expect(!isManyItemPtr(@TypeOf(array[0..1])));
259}259}
260260
261///261///
...@@ -269,9 +269,9 @@ pub fn isSlice(comptime T: type) bool {...@@ -269,9 +269,9 @@ pub fn isSlice(comptime T: type) bool {
269269
270test "std.meta.trait.isSlice" {270test "std.meta.trait.isSlice" {
271 const array = [_]u8{0} ** 10;271 const array = [_]u8{0} ** 10;
272 testing.expect(isSlice(@typeOf(array[0..])));272 testing.expect(isSlice(@TypeOf(array[0..])));
273 testing.expect(!isSlice(@typeOf(array)));273 testing.expect(!isSlice(@TypeOf(array)));
274 testing.expect(!isSlice(@typeOf(&array[0])));274 testing.expect(!isSlice(@TypeOf(&array[0])));
275}275}
276276
277///277///
...@@ -291,10 +291,10 @@ test "std.meta.trait.isIndexable" {...@@ -291,10 +291,10 @@ test "std.meta.trait.isIndexable" {
291 const array = [_]u8{0} ** 10;291 const array = [_]u8{0} ** 10;
292 const slice = array[0..];292 const slice = array[0..];
293293
294 testing.expect(isIndexable(@typeOf(array)));294 testing.expect(isIndexable(@TypeOf(array)));
295 testing.expect(isIndexable(@typeOf(&array)));295 testing.expect(isIndexable(@TypeOf(&array)));
296 testing.expect(isIndexable(@typeOf(slice)));296 testing.expect(isIndexable(@TypeOf(slice)));
297 testing.expect(!isIndexable(meta.Child(@typeOf(slice))));297 testing.expect(!isIndexable(meta.Child(@TypeOf(slice))));
298}298}
299299
300///300///
...@@ -313,8 +313,8 @@ test "std.meta.trait.isNumber" {...@@ -313,8 +313,8 @@ test "std.meta.trait.isNumber" {
313 testing.expect(isNumber(u32));313 testing.expect(isNumber(u32));
314 testing.expect(isNumber(f32));314 testing.expect(isNumber(f32));
315 testing.expect(isNumber(u64));315 testing.expect(isNumber(u64));
316 testing.expect(isNumber(@typeOf(102)));316 testing.expect(isNumber(@TypeOf(102)));
317 testing.expect(isNumber(@typeOf(102.123)));317 testing.expect(isNumber(@TypeOf(102.123)));
318 testing.expect(!isNumber([]u8));318 testing.expect(!isNumber([]u8));
319 testing.expect(!isNumber(NotANumber));319 testing.expect(!isNumber(NotANumber));
320}320}
...@@ -328,10 +328,10 @@ pub fn isConstPtr(comptime T: type) bool {...@@ -328,10 +328,10 @@ pub fn isConstPtr(comptime T: type) bool {
328test "std.meta.trait.isConstPtr" {328test "std.meta.trait.isConstPtr" {
329 var t = @as(u8, 0);329 var t = @as(u8, 0);
330 const c = @as(u8, 0);330 const c = @as(u8, 0);
331 testing.expect(isConstPtr(*const @typeOf(t)));331 testing.expect(isConstPtr(*const @TypeOf(t)));
332 testing.expect(isConstPtr(@typeOf(&c)));332 testing.expect(isConstPtr(@TypeOf(&c)));
333 testing.expect(!isConstPtr(*@typeOf(t)));333 testing.expect(!isConstPtr(*@TypeOf(t)));
334 testing.expect(!isConstPtr(@typeOf(6)));334 testing.expect(!isConstPtr(@TypeOf(6)));
335}335}
336336
337pub fn isContainer(comptime T: type) bool {337pub fn isContainer(comptime T: type) bool {
lib/std/mutex.zig+1-1
...@@ -11,7 +11,7 @@ const ResetEvent = std.ResetEvent;...@@ -11,7 +11,7 @@ const ResetEvent = std.ResetEvent;
11/// no-ops. In single threaded debug mode, there is deadlock detection.11/// no-ops. In single threaded debug mode, there is deadlock detection.
12pub const Mutex = if (builtin.single_threaded)12pub const Mutex = if (builtin.single_threaded)
13 struct {13 struct {
14 lock: @typeOf(lock_init),14 lock: @TypeOf(lock_init),
1515
16 const lock_init = if (std.debug.runtime_safety) false else {};16 const lock_init = if (std.debug.runtime_safety) false else {};
1717
lib/std/net.zig+1-1
...@@ -271,7 +271,7 @@ pub const Address = extern union {...@@ -271,7 +271,7 @@ pub const Address = extern union {
271 options: std.fmt.FormatOptions,271 options: std.fmt.FormatOptions,
272 context: var,272 context: var,
273 comptime Errors: type,273 comptime Errors: type,
274 output: fn (@typeOf(context), []const u8) Errors!void,274 output: fn (@TypeOf(context), []const u8) Errors!void,
275 ) !void {275 ) !void {
276 switch (self.any.family) {276 switch (self.any.family) {
277 os.AF_INET => {277 os.AF_INET => {
lib/std/os.zig+1-1
...@@ -2974,7 +2974,7 @@ pub fn res_mkquery(...@@ -2974,7 +2974,7 @@ pub fn res_mkquery(
2974 // Make a reasonably unpredictable id2974 // Make a reasonably unpredictable id
2975 var ts: timespec = undefined;2975 var ts: timespec = undefined;
2976 clock_gettime(CLOCK_REALTIME, &ts) catch {};2976 clock_gettime(CLOCK_REALTIME, &ts) catch {};
2977 const UInt = @IntType(false, @typeOf(ts.tv_nsec).bit_count);2977 const UInt = @IntType(false, @TypeOf(ts.tv_nsec).bit_count);
2978 const unsec = @bitCast(UInt, ts.tv_nsec);2978 const unsec = @bitCast(UInt, ts.tv_nsec);
2979 const id = @truncate(u32, unsec + unsec / 65536);2979 const id = @truncate(u32, unsec + unsec / 65536);
2980 q[0] = @truncate(u8, id / 256);2980 q[0] = @truncate(u8, id / 256);
lib/std/os/linux.zig+2-2
...@@ -706,7 +706,7 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti...@@ -706,7 +706,7 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti
706 .restorer = @ptrCast(extern fn () void, restorer_fn),706 .restorer = @ptrCast(extern fn () void, restorer_fn),
707 };707 };
708 var ksa_old: k_sigaction = undefined;708 var ksa_old: k_sigaction = undefined;
709 const ksa_mask_size = @sizeOf(@typeOf(ksa_old.mask));709 const ksa_mask_size = @sizeOf(@TypeOf(ksa_old.mask));
710 @memcpy(@ptrCast([*]u8, &ksa.mask), @ptrCast([*]const u8, &act.mask), ksa_mask_size);710 @memcpy(@ptrCast([*]u8, &ksa.mask), @ptrCast([*]const u8, &act.mask), ksa_mask_size);
711 const result = syscall4(SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), ksa_mask_size);711 const result = syscall4(SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), ksa_mask_size);
712 const err = getErrno(result);712 const err = getErrno(result);
...@@ -786,7 +786,7 @@ pub fn sendmsg(fd: i32, msg: *msghdr_const, flags: u32) usize {...@@ -786,7 +786,7 @@ pub fn sendmsg(fd: i32, msg: *msghdr_const, flags: u32) usize {
786}786}
787787
788pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize {788pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize {
789 if (@typeInfo(usize).Int.bits > @typeInfo(@typeOf(mmsghdr(undefined).msg_len)).Int.bits) {789 if (@typeInfo(usize).Int.bits > @typeInfo(@TypeOf(mmsghdr(undefined).msg_len)).Int.bits) {
790 // workaround kernel brokenness:790 // workaround kernel brokenness:
791 // if adding up all iov_len overflows a i32 then split into multiple calls791 // if adding up all iov_len overflows a i32 then split into multiple calls
792 // see https://www.openwall.com/lists/musl/2014/06/07/5792 // see https://www.openwall.com/lists/musl/2014/06/07/5
lib/std/os/uefi.zig+1-1
...@@ -32,7 +32,7 @@ pub const Guid = extern struct {...@@ -32,7 +32,7 @@ pub const Guid = extern struct {
32 options: fmt.FormatOptions,32 options: fmt.FormatOptions,
33 context: var,33 context: var,
34 comptime Errors: type,34 comptime Errors: type,
35 output: fn (@typeOf(context), []const u8) Errors!void,35 output: fn (@TypeOf(context), []const u8) Errors!void,
36 ) Errors!void {36 ) Errors!void {
37 if (f.len == 0) {37 if (f.len == 0) {
38 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);38 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);
lib/std/os/windows/kernel32.zig+2-2
...@@ -214,12 +214,12 @@ pub extern "kernel32" stdcallcc fn WaitForSingleObject(hHandle: HANDLE, dwMillis...@@ -214,12 +214,12 @@ pub extern "kernel32" stdcallcc fn WaitForSingleObject(hHandle: HANDLE, dwMillis
214214
215pub extern "kernel32" stdcallcc fn WaitForSingleObjectEx(hHandle: HANDLE, dwMilliseconds: DWORD, bAlertable: BOOL) DWORD;215pub extern "kernel32" stdcallcc fn WaitForSingleObjectEx(hHandle: HANDLE, dwMilliseconds: DWORD, bAlertable: BOOL) DWORD;
216216
217pub extern "kernel32" stdcallcc fn WaitForMultipleObjects(nCount: DWORD, lpHandle: [*]const HANDLE, bWaitAll:BOOL, dwMilliseconds: DWORD) DWORD;217pub extern "kernel32" stdcallcc fn WaitForMultipleObjects(nCount: DWORD, lpHandle: [*]const HANDLE, bWaitAll: BOOL, dwMilliseconds: DWORD) DWORD;
218218
219pub extern "kernel32" stdcallcc fn WaitForMultipleObjectsEx(219pub extern "kernel32" stdcallcc fn WaitForMultipleObjectsEx(
220 nCount: DWORD,220 nCount: DWORD,
221 lpHandle: [*]const HANDLE,221 lpHandle: [*]const HANDLE,
222 bWaitAll:BOOL,222 bWaitAll: BOOL,
223 dwMilliseconds: DWORD,223 dwMilliseconds: DWORD,
224 bAlertable: BOOL,224 bAlertable: BOOL,
225) DWORD;225) DWORD;
lib/std/pdb.zig+1-1
...@@ -635,7 +635,7 @@ const MsfStream = struct {...@@ -635,7 +635,7 @@ const MsfStream = struct {
635 /// Implementation of InStream trait for Pdb.MsfStream635 /// Implementation of InStream trait for Pdb.MsfStream
636 stream: Stream = undefined,636 stream: Stream = undefined,
637637
638 pub const Error = @typeOf(read).ReturnType.ErrorSet;638 pub const Error = @TypeOf(read).ReturnType.ErrorSet;
639 pub const Stream = io.InStream(Error);639 pub const Stream = io.InStream(Error);
640640
641 fn init(block_size: u32, file: File, blocks: []u32) MsfStream {641 fn init(block_size: u32, file: File, blocks: []u32) MsfStream {
lib/std/reset_event.zig+7-7
...@@ -27,7 +27,7 @@ pub const ResetEvent = struct {...@@ -27,7 +27,7 @@ pub const ResetEvent = struct {
27 pub fn isSet(self: *ResetEvent) bool {27 pub fn isSet(self: *ResetEvent) bool {
28 return self.os_event.isSet();28 return self.os_event.isSet();
29 }29 }
30 30
31 /// Sets the event if not already set and31 /// Sets the event if not already set and
32 /// wakes up AT LEAST one thread waiting the event.32 /// wakes up AT LEAST one thread waiting the event.
33 /// Returns whether or not a thread was woken up.33 /// Returns whether or not a thread was woken up.
...@@ -62,7 +62,7 @@ const OsEvent = if (builtin.single_threaded) DebugEvent else switch (builtin.os)...@@ -62,7 +62,7 @@ const OsEvent = if (builtin.single_threaded) DebugEvent else switch (builtin.os)
62};62};
6363
64const DebugEvent = struct {64const DebugEvent = struct {
65 is_set: @typeOf(set_init),65 is_set: @TypeOf(set_init),
6666
67 const set_init = if (std.debug.runtime_safety) false else {};67 const set_init = if (std.debug.runtime_safety) false else {};
6868
...@@ -283,7 +283,7 @@ const PosixEvent = struct {...@@ -283,7 +283,7 @@ const PosixEvent = struct {
283283
284 pub fn init() PosixEvent {284 pub fn init() PosixEvent {
285 return PosixEvent{285 return PosixEvent{
286 .state = .0,286 .state = 0,
287 .cond = c.PTHREAD_COND_INITIALIZER,287 .cond = c.PTHREAD_COND_INITIALIZER,
288 .mutex = c.PTHREAD_MUTEX_INITIALIZER,288 .mutex = c.PTHREAD_MUTEX_INITIALIZER,
289 };289 };
...@@ -345,8 +345,8 @@ const PosixEvent = struct {...@@ -345,8 +345,8 @@ const PosixEvent = struct {
345 timeout_abs += @intCast(u64, ts.tv_sec) * time.second;345 timeout_abs += @intCast(u64, ts.tv_sec) * time.second;
346 timeout_abs += @intCast(u64, ts.tv_nsec);346 timeout_abs += @intCast(u64, ts.tv_nsec);
347 }347 }
348 ts.tv_sec = @intCast(@typeOf(ts.tv_sec), @divFloor(timeout_abs, time.second));348 ts.tv_sec = @intCast(@TypeOf(ts.tv_sec), @divFloor(timeout_abs, time.second));
349 ts.tv_nsec = @intCast(@typeOf(ts.tv_nsec), @mod(timeout_abs, time.second));349 ts.tv_nsec = @intCast(@TypeOf(ts.tv_nsec), @mod(timeout_abs, time.second));
350 }350 }
351351
352 var dummy_value: u32 = undefined;352 var dummy_value: u32 = undefined;
...@@ -426,8 +426,8 @@ test "std.ResetEvent" {...@@ -426,8 +426,8 @@ test "std.ResetEvent" {
426 .event = event,426 .event = event,
427 .value = 0,427 .value = 0,
428 };428 };
429 429
430 var receiver = try std.Thread.spawn(&context, Context.receiver);430 var receiver = try std.Thread.spawn(&context, Context.receiver);
431 defer receiver.wait();431 defer receiver.wait();
432 try context.sender();432 try context.sender();
433}
\ No newline at end of file
433}
lib/std/segmented_list.zig+2-2
...@@ -122,7 +122,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -122,7 +122,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
122 self.* = undefined;122 self.* = undefined;
123 }123 }
124124
125 pub fn at(self: var, i: usize) AtType(@typeOf(self)) {125 pub fn at(self: var, i: usize) AtType(@TypeOf(self)) {
126 assert(i < self.len);126 assert(i < self.len);
127 return self.uncheckedAt(i);127 return self.uncheckedAt(i);
128 }128 }
...@@ -213,7 +213,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type...@@ -213,7 +213,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type
213 self.len = new_len;213 self.len = new_len;
214 }214 }
215215
216 pub fn uncheckedAt(self: var, index: usize) AtType(@typeOf(self)) {216 pub fn uncheckedAt(self: var, index: usize) AtType(@TypeOf(self)) {
217 if (index < prealloc_item_count) {217 if (index < prealloc_item_count) {
218 return &self.prealloc_segment[index];218 return &self.prealloc_segment[index];
219 }219 }
lib/std/special/build_runner.zig+1-1
...@@ -125,7 +125,7 @@ pub fn main() !void {...@@ -125,7 +125,7 @@ pub fn main() !void {
125}125}
126126
127fn runBuild(builder: *Builder) anyerror!void {127fn runBuild(builder: *Builder) anyerror!void {
128 switch (@typeId(@typeOf(root.build).ReturnType)) {128 switch (@typeId(@TypeOf(root.build).ReturnType)) {
129 .Void => root.build(builder),129 .Void => root.build(builder),
130 .ErrorUnion => try root.build(builder),130 .ErrorUnion => try root.build(builder),
131 else => @compileError("expected return type of build to be 'void' or '!void'"),131 else => @compileError("expected return type of build to be 'void' or '!void'"),
lib/std/special/compiler_rt.zig+4-4
...@@ -384,7 +384,7 @@ extern fn __aeabi_uidivmod(n: u32, d: u32) extern struct {...@@ -384,7 +384,7 @@ extern fn __aeabi_uidivmod(n: u32, d: u32) extern struct {
384} {384} {
385 @setRuntimeSafety(is_test);385 @setRuntimeSafety(is_test);
386386
387 var result: @typeOf(__aeabi_uidivmod).ReturnType = undefined;387 var result: @TypeOf(__aeabi_uidivmod).ReturnType = undefined;
388 result.q = __udivmodsi4(n, d, &result.r);388 result.q = __udivmodsi4(n, d, &result.r);
389 return result;389 return result;
390}390}
...@@ -395,7 +395,7 @@ extern fn __aeabi_uldivmod(n: u64, d: u64) extern struct {...@@ -395,7 +395,7 @@ extern fn __aeabi_uldivmod(n: u64, d: u64) extern struct {
395} {395} {
396 @setRuntimeSafety(is_test);396 @setRuntimeSafety(is_test);
397397
398 var result: @typeOf(__aeabi_uldivmod).ReturnType = undefined;398 var result: @TypeOf(__aeabi_uldivmod).ReturnType = undefined;
399 result.q = __udivmoddi4(n, d, &result.r);399 result.q = __udivmoddi4(n, d, &result.r);
400 return result;400 return result;
401}401}
...@@ -406,7 +406,7 @@ extern fn __aeabi_idivmod(n: i32, d: i32) extern struct {...@@ -406,7 +406,7 @@ extern fn __aeabi_idivmod(n: i32, d: i32) extern struct {
406} {406} {
407 @setRuntimeSafety(is_test);407 @setRuntimeSafety(is_test);
408408
409 var result: @typeOf(__aeabi_idivmod).ReturnType = undefined;409 var result: @TypeOf(__aeabi_idivmod).ReturnType = undefined;
410 result.q = __divmodsi4(n, d, &result.r);410 result.q = __divmodsi4(n, d, &result.r);
411 return result;411 return result;
412}412}
...@@ -417,7 +417,7 @@ extern fn __aeabi_ldivmod(n: i64, d: i64) extern struct {...@@ -417,7 +417,7 @@ extern fn __aeabi_ldivmod(n: i64, d: i64) extern struct {
417} {417} {
418 @setRuntimeSafety(is_test);418 @setRuntimeSafety(is_test);
419419
420 var result: @typeOf(__aeabi_ldivmod).ReturnType = undefined;420 var result: @TypeOf(__aeabi_ldivmod).ReturnType = undefined;
421 result.q = __divmoddi4(n, d, &result.r);421 result.q = __divmoddi4(n, d, &result.r);
422 return result;422 return result;
423}423}
lib/std/special/start.zig+4-4
...@@ -25,7 +25,7 @@ comptime {...@@ -25,7 +25,7 @@ comptime {
25 }25 }
26 } else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) {26 } else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) {
27 if (builtin.link_libc and @hasDecl(root, "main")) {27 if (builtin.link_libc and @hasDecl(root, "main")) {
28 if (@typeInfo(@typeOf(root.main)).Fn.calling_convention != .C) {28 if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) {
29 @export("main", main, .Weak);29 @export("main", main, .Weak);
30 }30 }
31 } else if (builtin.os == .windows) {31 } else if (builtin.os == .windows) {
...@@ -69,7 +69,7 @@ extern fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) u...@@ -69,7 +69,7 @@ extern fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) u
69 uefi.handle = handle;69 uefi.handle = handle;
70 uefi.system_table = system_table;70 uefi.system_table = system_table;
7171
72 switch (@typeInfo(@typeOf(root.main).ReturnType)) {72 switch (@typeInfo(@TypeOf(root.main).ReturnType)) {
73 .NoReturn => {73 .NoReturn => {
74 root.main();74 root.main();
75 },75 },
...@@ -248,7 +248,7 @@ async fn callMainAsync(loop: *std.event.Loop) u8 {...@@ -248,7 +248,7 @@ async fn callMainAsync(loop: *std.event.Loop) u8 {
248// This is not marked inline because it is called with @asyncCall when248// This is not marked inline because it is called with @asyncCall when
249// there is an event loop.249// there is an event loop.
250fn callMain() u8 {250fn callMain() u8 {
251 switch (@typeInfo(@typeOf(root.main).ReturnType)) {251 switch (@typeInfo(@TypeOf(root.main).ReturnType)) {
252 .NoReturn => {252 .NoReturn => {
253 root.main();253 root.main();
254 },254 },
...@@ -270,7 +270,7 @@ fn callMain() u8 {...@@ -270,7 +270,7 @@ fn callMain() u8 {
270 }270 }
271 return 1;271 return 1;
272 };272 };
273 switch (@typeInfo(@typeOf(result))) {273 switch (@typeInfo(@TypeOf(result))) {
274 .Void => return 0,274 .Void => return 0,
275 .Int => |info| {275 .Int => |info| {
276 if (info.bits != 8) {276 if (info.bits != 8) {
lib/std/testing.zig+5-5
...@@ -21,14 +21,14 @@ pub fn expectError(expected_error: anyerror, actual_error_union: var) void {...@@ -21,14 +21,14 @@ pub fn expectError(expected_error: anyerror, actual_error_union: var) void {
21/// equal, prints diagnostics to stderr to show exactly how they are not equal,21/// equal, prints diagnostics to stderr to show exactly how they are not equal,
22/// then aborts.22/// then aborts.
23/// The types must match exactly.23/// The types must match exactly.
24pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {24pub fn expectEqual(expected: var, actual: @TypeOf(expected)) void {
25 switch (@typeInfo(@typeOf(actual))) {25 switch (@typeInfo(@TypeOf(actual))) {
26 .NoReturn,26 .NoReturn,
27 .BoundFn,27 .BoundFn,
28 .Opaque,28 .Opaque,
29 .Frame,29 .Frame,
30 .AnyFrame,30 .AnyFrame,
31 => @compileError("value of type " ++ @typeName(@typeOf(actual)) ++ " encountered"),31 => @compileError("value of type " ++ @typeName(@TypeOf(actual)) ++ " encountered"),
3232
33 .Undefined,33 .Undefined,
34 .Null,34 .Null,
...@@ -87,7 +87,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {...@@ -87,7 +87,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
87 @compileError("Unable to compare untagged union values");87 @compileError("Unable to compare untagged union values");
88 }88 }
8989
90 const TagType = @TagType(@typeOf(expected));90 const TagType = @TagType(@TypeOf(expected));
9191
92 const expectedTag = @as(TagType, expected);92 const expectedTag = @as(TagType, expected);
93 const actualTag = @as(TagType, actual);93 const actualTag = @as(TagType, actual);
...@@ -95,7 +95,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {...@@ -95,7 +95,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
95 expectEqual(expectedTag, actualTag);95 expectEqual(expectedTag, actualTag);
9696
97 // we only reach this loop if the tags are equal97 // we only reach this loop if the tags are equal
98 inline for (std.meta.fields(@typeOf(actual))) |fld| {98 inline for (std.meta.fields(@TypeOf(actual))) |fld| {
99 if (std.mem.eql(u8, fld.name, @tagName(actualTag))) {99 if (std.mem.eql(u8, fld.name, @tagName(actualTag))) {
100 expectEqual(@field(expected, fld.name), @field(actual, fld.name));100 expectEqual(@field(expected, fld.name), @field(actual, fld.name));
101 return;101 return;
lib/std/thread.zig+5-5
...@@ -138,7 +138,7 @@ pub const Thread = struct {...@@ -138,7 +138,7 @@ pub const Thread = struct {
138 };138 };
139139
140 /// caller must call wait on the returned thread140 /// caller must call wait on the returned thread
141 /// fn startFn(@typeOf(context)) T141 /// fn startFn(@TypeOf(context)) T
142 /// where T is u8, noreturn, void, or !void142 /// where T is u8, noreturn, void, or !void
143 /// caller must call wait on the returned thread143 /// caller must call wait on the returned thread
144 pub fn spawn(context: var, comptime startFn: var) SpawnError!*Thread {144 pub fn spawn(context: var, comptime startFn: var) SpawnError!*Thread {
...@@ -147,8 +147,8 @@ pub const Thread = struct {...@@ -147,8 +147,8 @@ pub const Thread = struct {
147 // https://github.com/ziglang/zig/issues/157147 // https://github.com/ziglang/zig/issues/157
148 const default_stack_size = 16 * 1024 * 1024;148 const default_stack_size = 16 * 1024 * 1024;
149149
150 const Context = @typeOf(context);150 const Context = @TypeOf(context);
151 comptime assert(@ArgType(@typeOf(startFn), 0) == Context);151 comptime assert(@ArgType(@TypeOf(startFn), 0) == Context);
152152
153 if (builtin.os == builtin.Os.windows) {153 if (builtin.os == builtin.Os.windows) {
154 const WinThread = struct {154 const WinThread = struct {
...@@ -158,7 +158,7 @@ pub const Thread = struct {...@@ -158,7 +158,7 @@ pub const Thread = struct {
158 };158 };
159 extern fn threadMain(raw_arg: windows.LPVOID) windows.DWORD {159 extern fn threadMain(raw_arg: windows.LPVOID) windows.DWORD {
160 const arg = if (@sizeOf(Context) == 0) {} else @ptrCast(*Context, @alignCast(@alignOf(Context), raw_arg)).*;160 const arg = if (@sizeOf(Context) == 0) {} else @ptrCast(*Context, @alignCast(@alignOf(Context), raw_arg)).*;
161 switch (@typeId(@typeOf(startFn).ReturnType)) {161 switch (@typeId(@TypeOf(startFn).ReturnType)) {
162 .Int => {162 .Int => {
163 return startFn(arg);163 return startFn(arg);
164 },164 },
...@@ -201,7 +201,7 @@ pub const Thread = struct {...@@ -201,7 +201,7 @@ pub const Thread = struct {
201 extern fn linuxThreadMain(ctx_addr: usize) u8 {201 extern fn linuxThreadMain(ctx_addr: usize) u8 {
202 const arg = if (@sizeOf(Context) == 0) {} else @intToPtr(*const Context, ctx_addr).*;202 const arg = if (@sizeOf(Context) == 0) {} else @intToPtr(*const Context, ctx_addr).*;
203203
204 switch (@typeId(@typeOf(startFn).ReturnType)) {204 switch (@typeId(@TypeOf(startFn).ReturnType)) {
205 .Int => {205 .Int => {
206 return startFn(arg);206 return startFn(arg);
207 },207 },
lib/std/zig/parser_test.zig+13-2
...@@ -1,3 +1,14 @@...@@ -1,3 +1,14 @@
1// TODO: Remove condition after deprecating 'typeOf'. See https://github.com/ziglang/zig/issues/1348
2test "zig fmt: change @typeOf to @TypeOf" {
3 try testTransform(
4 \\const a = @typeOf(@as(usize, 10));
5 \\
6 ,
7 \\const a = @TypeOf(@as(usize, 10));
8 \\
9 );
10}
11
1test "zig fmt: comptime struct field" {12test "zig fmt: comptime struct field" {
2 try testCanonical(13 try testCanonical(
3 \\const Foo = struct {14 \\const Foo = struct {
...@@ -1060,7 +1071,7 @@ test "zig fmt: line comment after doc comment" {...@@ -1060,7 +1071,7 @@ test "zig fmt: line comment after doc comment" {
1060test "zig fmt: float literal with exponent" {1071test "zig fmt: float literal with exponent" {
1061 try testCanonical(1072 try testCanonical(
1062 \\test "bit field alignment" {1073 \\test "bit field alignment" {
1063 \\ assert(@typeOf(&blah.b) == *align(1:3:6) const u3);1074 \\ assert(@TypeOf(&blah.b) == *align(1:3:6) const u3);
1064 \\}1075 \\}
1065 \\1076 \\
1066 );1077 );
...@@ -2593,7 +2604,7 @@ test "zig fmt: comments at several places in struct init" {...@@ -2593,7 +2604,7 @@ test "zig fmt: comments at several places in struct init" {
2593 try testTransform(2604 try testTransform(
2594 \\var bar = Bar{2605 \\var bar = Bar{
2595 \\ .x = 10, // test2606 \\ .x = 10, // test
2596 \\ .y = "test" 2607 \\ .y = "test"
2597 \\ // test2608 \\ // test
2598 \\};2609 \\};
2599 \\2610 \\
lib/std/zig/render.zig+22-16
...@@ -13,19 +13,19 @@ pub const Error = error{...@@ -13,19 +13,19 @@ pub const Error = error{
13};13};
1414
15/// Returns whether anything changed15/// Returns whether anything changed
16pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@typeOf(stream).Child.Error || Error)!bool {16pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@TypeOf(stream).Child.Error || Error)!bool {
17 comptime assert(@typeId(@typeOf(stream)) == builtin.TypeId.Pointer);17 comptime assert(@typeId(@TypeOf(stream)) == builtin.TypeId.Pointer);
1818
19 var anything_changed: bool = false;19 var anything_changed: bool = false;
2020
21 // make a passthrough stream that checks whether something changed21 // make a passthrough stream that checks whether something changed
22 const MyStream = struct {22 const MyStream = struct {
23 const MyStream = @This();23 const MyStream = @This();
24 const StreamError = @typeOf(stream).Child.Error;24 const StreamError = @TypeOf(stream).Child.Error;
25 const Stream = std.io.OutStream(StreamError);25 const Stream = std.io.OutStream(StreamError);
2626
27 anything_changed_ptr: *bool,27 anything_changed_ptr: *bool,
28 child_stream: @typeOf(stream),28 child_stream: @TypeOf(stream),
29 stream: Stream,29 stream: Stream,
30 source_index: usize,30 source_index: usize,
31 source: []const u8,31 source: []const u8,
...@@ -70,7 +70,7 @@ fn renderRoot(...@@ -70,7 +70,7 @@ fn renderRoot(
70 allocator: *mem.Allocator,70 allocator: *mem.Allocator,
71 stream: var,71 stream: var,
72 tree: *ast.Tree,72 tree: *ast.Tree,
73) (@typeOf(stream).Child.Error || Error)!void {73) (@TypeOf(stream).Child.Error || Error)!void {
74 var tok_it = tree.tokens.iterator(0);74 var tok_it = tree.tokens.iterator(0);
7575
76 // render all the line comments at the beginning of the file76 // render all the line comments at the beginning of the file
...@@ -190,7 +190,7 @@ fn renderRoot(...@@ -190,7 +190,7 @@ fn renderRoot(
190 }190 }
191}191}
192192
193fn renderExtraNewline(tree: *ast.Tree, stream: var, start_col: *usize, node: *ast.Node) @typeOf(stream).Child.Error!void {193fn renderExtraNewline(tree: *ast.Tree, stream: var, start_col: *usize, node: *ast.Node) @TypeOf(stream).Child.Error!void {
194 const first_token = node.firstToken();194 const first_token = node.firstToken();
195 var prev_token = first_token;195 var prev_token = first_token;
196 while (tree.tokens.at(prev_token - 1).id == .DocComment) {196 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...@@ -204,7 +204,7 @@ fn renderExtraNewline(tree: *ast.Tree, stream: var, start_col: *usize, node: *as
204 }204 }
205}205}
206206
207fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, indent: usize, start_col: *usize, decl: *ast.Node) (@typeOf(stream).Child.Error || Error)!void {207fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, indent: usize, start_col: *usize, decl: *ast.Node) (@TypeOf(stream).Child.Error || Error)!void {
208 switch (decl.id) {208 switch (decl.id) {
209 .FnProto => {209 .FnProto => {
210 const fn_proto = @fieldParentPtr(ast.Node.FnProto, "base", decl);210 const fn_proto = @fieldParentPtr(ast.Node.FnProto, "base", decl);
...@@ -325,7 +325,7 @@ fn renderExpression(...@@ -325,7 +325,7 @@ fn renderExpression(
325 start_col: *usize,325 start_col: *usize,
326 base: *ast.Node,326 base: *ast.Node,
327 space: Space,327 space: Space,
328) (@typeOf(stream).Child.Error || Error)!void {328) (@TypeOf(stream).Child.Error || Error)!void {
329 switch (base.id) {329 switch (base.id) {
330 .Identifier => {330 .Identifier => {
331 const identifier = @fieldParentPtr(ast.Node.Identifier, "base", base);331 const identifier = @fieldParentPtr(ast.Node.Identifier, "base", base);
...@@ -1249,7 +1249,13 @@ fn renderExpression(...@@ -1249,7 +1249,13 @@ fn renderExpression(
1249 .BuiltinCall => {1249 .BuiltinCall => {
1250 const builtin_call = @fieldParentPtr(ast.Node.BuiltinCall, "base", base);1250 const builtin_call = @fieldParentPtr(ast.Node.BuiltinCall, "base", base);
12511251
1252 try renderToken(tree, stream, builtin_call.builtin_token, indent, start_col, Space.None); // @name1252 // TODO: Remove condition after deprecating 'typeOf'. See https://github.com/ziglang/zig/issues/1348
1253 if (mem.eql(u8, tree.tokenSlicePtr(tree.tokens.at(builtin_call.builtin_token)), "@typeOf")) {
1254 try stream.write("@TypeOf");
1255 } else {
1256 try renderToken(tree, stream, builtin_call.builtin_token, indent, start_col, Space.None); // @name
1257 }
1258
1253 try renderToken(tree, stream, tree.nextToken(builtin_call.builtin_token), indent, start_col, Space.None); // (1259 try renderToken(tree, stream, tree.nextToken(builtin_call.builtin_token), indent, start_col, Space.None); // (
12541260
1255 var it = builtin_call.params.iterator(0);1261 var it = builtin_call.params.iterator(0);
...@@ -1897,7 +1903,7 @@ fn renderVarDecl(...@@ -1897,7 +1903,7 @@ fn renderVarDecl(
1897 indent: usize,1903 indent: usize,
1898 start_col: *usize,1904 start_col: *usize,
1899 var_decl: *ast.Node.VarDecl,1905 var_decl: *ast.Node.VarDecl,
1900) (@typeOf(stream).Child.Error || Error)!void {1906) (@TypeOf(stream).Child.Error || Error)!void {
1901 if (var_decl.visib_token) |visib_token| {1907 if (var_decl.visib_token) |visib_token| {
1902 try renderToken(tree, stream, visib_token, indent, start_col, Space.Space); // pub1908 try renderToken(tree, stream, visib_token, indent, start_col, Space.Space); // pub
1903 }1909 }
...@@ -1970,7 +1976,7 @@ fn renderParamDecl(...@@ -1970,7 +1976,7 @@ fn renderParamDecl(
1970 start_col: *usize,1976 start_col: *usize,
1971 base: *ast.Node,1977 base: *ast.Node,
1972 space: Space,1978 space: Space,
1973) (@typeOf(stream).Child.Error || Error)!void {1979) (@TypeOf(stream).Child.Error || Error)!void {
1974 const param_decl = @fieldParentPtr(ast.Node.ParamDecl, "base", base);1980 const param_decl = @fieldParentPtr(ast.Node.ParamDecl, "base", base);
19751981
1976 try renderDocComments(tree, stream, param_decl, indent, start_col);1982 try renderDocComments(tree, stream, param_decl, indent, start_col);
...@@ -1999,7 +2005,7 @@ fn renderStatement(...@@ -1999,7 +2005,7 @@ fn renderStatement(
1999 indent: usize,2005 indent: usize,
2000 start_col: *usize,2006 start_col: *usize,
2001 base: *ast.Node,2007 base: *ast.Node,
2002) (@typeOf(stream).Child.Error || Error)!void {2008) (@TypeOf(stream).Child.Error || Error)!void {
2003 switch (base.id) {2009 switch (base.id) {
2004 .VarDecl => {2010 .VarDecl => {
2005 const var_decl = @fieldParentPtr(ast.Node.VarDecl, "base", base);2011 const var_decl = @fieldParentPtr(ast.Node.VarDecl, "base", base);
...@@ -2038,7 +2044,7 @@ fn renderTokenOffset(...@@ -2038,7 +2044,7 @@ fn renderTokenOffset(
2038 start_col: *usize,2044 start_col: *usize,
2039 space: Space,2045 space: Space,
2040 token_skip_bytes: usize,2046 token_skip_bytes: usize,
2041) (@typeOf(stream).Child.Error || Error)!void {2047) (@TypeOf(stream).Child.Error || Error)!void {
2042 if (space == Space.BlockStart) {2048 if (space == Space.BlockStart) {
2043 if (start_col.* < indent + indent_delta)2049 if (start_col.* < indent + indent_delta)
2044 return renderToken(tree, stream, token_index, indent, start_col, Space.Space);2050 return renderToken(tree, stream, token_index, indent, start_col, Space.Space);
...@@ -2226,7 +2232,7 @@ fn renderToken(...@@ -2226,7 +2232,7 @@ fn renderToken(
2226 indent: usize,2232 indent: usize,
2227 start_col: *usize,2233 start_col: *usize,
2228 space: Space,2234 space: Space,
2229) (@typeOf(stream).Child.Error || Error)!void {2235) (@TypeOf(stream).Child.Error || Error)!void {
2230 return renderTokenOffset(tree, stream, token_index, indent, start_col, space, 0);2236 return renderTokenOffset(tree, stream, token_index, indent, start_col, space, 0);
2231}2237}
22322238
...@@ -2236,7 +2242,7 @@ fn renderDocComments(...@@ -2236,7 +2242,7 @@ fn renderDocComments(
2236 node: var,2242 node: var,
2237 indent: usize,2243 indent: usize,
2238 start_col: *usize,2244 start_col: *usize,
2239) (@typeOf(stream).Child.Error || Error)!void {2245) (@TypeOf(stream).Child.Error || Error)!void {
2240 const comment = node.doc_comments orelse return;2246 const comment = node.doc_comments orelse return;
2241 var it = comment.lines.iterator(0);2247 var it = comment.lines.iterator(0);
2242 const first_token = node.firstToken();2248 const first_token = node.firstToken();
...@@ -2302,7 +2308,7 @@ const FindByteOutStream = struct {...@@ -2302,7 +2308,7 @@ const FindByteOutStream = struct {
2302 }2308 }
2303};2309};
23042310
2305fn copyFixingWhitespace(stream: var, slice: []const u8) @typeOf(stream).Child.Error!void {2311fn copyFixingWhitespace(stream: var, slice: []const u8) @TypeOf(stream).Child.Error!void {
2306 for (slice) |byte| switch (byte) {2312 for (slice) |byte| switch (byte) {
2307 '\t' => try stream.write(" "),2313 '\t' => try stream.write(" "),
2308 '\r' => {},2314 '\r' => {},
src-self-hosted/dep_tokenizer.zig+2-2
...@@ -1021,8 +1021,8 @@ comptime {...@@ -1021,8 +1021,8 @@ comptime {
1021// output: must be a function that takes a `self` idiom parameter1021// output: must be a function that takes a `self` idiom parameter
1022// and a bytes parameter1022// and a bytes parameter
1023// context: must be that self1023// context: must be that self
1024fn makeOutput(output: var, context: var) Output(@typeOf(output)) {1024fn makeOutput(output: var, context: var) Output(@TypeOf(output)) {
1025 return Output(@typeOf(output)){1025 return Output(@TypeOf(output)){
1026 .output = output,1026 .output = output,
1027 .context = context,1027 .context = context,
1028 };1028 };
src-self-hosted/ir.zig+1-1
...@@ -1807,7 +1807,7 @@ pub const Builder = struct {...@@ -1807,7 +1807,7 @@ pub const Builder = struct {
1807 // Look at the params and ref() other instructions1807 // Look at the params and ref() other instructions
1808 comptime var i = 0;1808 comptime var i = 0;
1809 inline while (i < @memberCount(I.Params)) : (i += 1) {1809 inline while (i < @memberCount(I.Params)) : (i += 1) {
1810 const FieldType = comptime @typeOf(@field(@as(I.Params, undefined), @memberName(I.Params, i)));1810 const FieldType = comptime @TypeOf(@field(@as(I.Params, undefined), @memberName(I.Params, i)));
1811 switch (FieldType) {1811 switch (FieldType) {
1812 *Inst => @field(inst.params, @memberName(I.Params, i)).ref(self),1812 *Inst => @field(inst.params, @memberName(I.Params, i)).ref(self),
1813 *BasicBlock => @field(inst.params, @memberName(I.Params, i)).ref(self),1813 *BasicBlock => @field(inst.params, @memberName(I.Params, i)).ref(self),
src-self-hosted/libc_installation.zig+1-1
...@@ -72,7 +72,7 @@ pub const LibCInstallation = struct {...@@ -72,7 +72,7 @@ pub const LibCInstallation = struct {
72 inline for (keys) |key, i| {72 inline for (keys) |key, i| {
73 if (std.mem.eql(u8, name, key)) {73 if (std.mem.eql(u8, name, key)) {
74 found_keys[i].found = true;74 found_keys[i].found = true;
75 switch (@typeInfo(@typeOf(@field(self, key)))) {75 switch (@typeInfo(@TypeOf(@field(self, key)))) {
76 .Optional => {76 .Optional => {
77 if (value.len == 0) {77 if (value.len == 0) {
78 @field(self, key) = null;78 @field(self, key) = null;
src-self-hosted/stage1.zig+4-6
...@@ -270,11 +270,9 @@ const FmtError = error{...@@ -270,11 +270,9 @@ const FmtError = error{
270 FileBusy,270 FileBusy,
271} || fs.File.OpenError;271} || fs.File.OpenError;
272272
273fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void {273fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void {
274 const file_path = try std.mem.dupe(fmt.allocator, u8, file_path_ref);274 if (fmt.seen.exists(file_path)) return;
275 defer fmt.allocator.free(file_path);275 try fmt.seen.put(file_path);
276
277 if (try fmt.seen.put(file_path, {})) |_| return;
278276
279 const source_code = io.readFileAlloc(fmt.allocator, file_path) catch |err| switch (err) {277 const source_code = io.readFileAlloc(fmt.allocator, file_path) catch |err| switch (err) {
280 error.IsDir, error.AccessDenied => {278 error.IsDir, error.AccessDenied => {
...@@ -341,7 +339,7 @@ const Fmt = struct {...@@ -341,7 +339,7 @@ const Fmt = struct {
341 color: errmsg.Color,339 color: errmsg.Color,
342 allocator: *mem.Allocator,340 allocator: *mem.Allocator,
343341
344 const SeenMap = std.StringHashMap(void);342 const SeenMap = std.BufSet;
345};343};
346344
347fn printErrMsgToFile(345fn printErrMsgToFile(
src-self-hosted/translate_c.zig+2-2
...@@ -1147,7 +1147,7 @@ fn transCreateNodeAPInt(c: *Context, int: ?*const ZigClangAPSInt) !*ast.Node {...@@ -1147,7 +1147,7 @@ fn transCreateNodeAPInt(c: *Context, int: ?*const ZigClangAPSInt) !*ast.Node {
1147 var big = try std.math.big.Int.initCapacity(c.a(), num_limbs);1147 var big = try std.math.big.Int.initCapacity(c.a(), num_limbs);
1148 defer big.deinit();1148 defer big.deinit();
1149 const data = ZigClangAPSInt_getRawData(int.?);1149 const data = ZigClangAPSInt_getRawData(int.?);
1150 var i: @typeOf(num_limbs) = 0;1150 var i: @TypeOf(num_limbs) = 0;
1151 while (i < num_limbs) : (i += 1) big.limbs[i] = data[i];1151 while (i < num_limbs) : (i += 1) big.limbs[i] = data[i];
1152 const str = big.toString(c.a(), 10) catch |err| switch (err) {1152 const str = big.toString(c.a(), 10) catch |err| switch (err) {
1153 error.OutOfMemory => return error.OutOfMemory,1153 error.OutOfMemory => return error.OutOfMemory,
...@@ -1416,7 +1416,7 @@ fn revertAndWarn(...@@ -1416,7 +1416,7 @@ fn revertAndWarn(
1416 source_loc: ZigClangSourceLocation,1416 source_loc: ZigClangSourceLocation,
1417 comptime format: []const u8,1417 comptime format: []const u8,
1418 args: var,1418 args: var,
1419) (@typeOf(err) || error{OutOfMemory}) {1419) (@TypeOf(err) || error{OutOfMemory}) {
1420 rp.activate();1420 rp.activate();
1421 try emitWarning(rp.c, source_loc, format, args);1421 try emitWarning(rp.c, source_loc, format, args);
1422 return err;1422 return err;
src-self-hosted/type.zig+3-3
...@@ -1038,14 +1038,14 @@ pub const Type = struct {...@@ -1038,14 +1038,14 @@ pub const Type = struct {
1038};1038};
10391039
1040fn hashAny(x: var, comptime seed: u64) u32 {1040fn hashAny(x: var, comptime seed: u64) u32 {
1041 switch (@typeInfo(@typeOf(x))) {1041 switch (@typeInfo(@TypeOf(x))) {
1042 .Int => |info| {1042 .Int => |info| {
1043 comptime var rng = comptime std.rand.DefaultPrng.init(seed);1043 comptime var rng = comptime std.rand.DefaultPrng.init(seed);
1044 const unsigned_x = @bitCast(@IntType(false, info.bits), x);1044 const unsigned_x = @bitCast(@IntType(false, info.bits), x);
1045 if (info.bits <= 32) {1045 if (info.bits <= 32) {
1046 return @as(u32, unsigned_x) *% comptime rng.random.scalar(u32);1046 return @as(u32, unsigned_x) *% comptime rng.random.scalar(u32);
1047 } else {1047 } else {
1048 return @truncate(u32, unsigned_x *% comptime rng.random.scalar(@typeOf(unsigned_x)));1048 return @truncate(u32, unsigned_x *% comptime rng.random.scalar(@TypeOf(unsigned_x)));
1049 }1049 }
1050 },1050 },
1051 .Pointer => |info| {1051 .Pointer => |info| {
...@@ -1069,6 +1069,6 @@ fn hashAny(x: var, comptime seed: u64) u32 {...@@ -1069,6 +1069,6 @@ fn hashAny(x: var, comptime seed: u64) u32 {
1069 return hashAny(@as(u32, 1), seed);1069 return hashAny(@as(u32, 1), seed);
1070 }1070 }
1071 },1071 },
1072 else => @compileError("implement hash function for " ++ @typeName(@typeOf(x))),1072 else => @compileError("implement hash function for " ++ @typeName(@TypeOf(x))),
1073 }1073 }
1074}1074}
src/all_types.hpp+1-1
...@@ -2393,7 +2393,7 @@ struct ScopeFnDef {...@@ -2393,7 +2393,7 @@ struct ScopeFnDef {
2393 ZigFn *fn_entry;2393 ZigFn *fn_entry;
2394};2394};
23952395
2396// This scope is created for a @typeOf.2396// This scope is created for a @TypeOf.
2397// All runtime side-effects are elided within it.2397// All runtime side-effects are elided within it.
2398// NodeTypeFnCallExpr2398// NodeTypeFnCallExpr
2399struct ScopeTypeOf {2399struct ScopeTypeOf {
src/analyze.cpp+2-2
...@@ -121,7 +121,7 @@ static ScopeExpr *find_expr_scope(Scope *scope) {...@@ -121,7 +121,7 @@ static ScopeExpr *find_expr_scope(Scope *scope) {
121}121}
122122
123static void update_progress_display(CodeGen *g) {123static void update_progress_display(CodeGen *g) {
124 stage2_progress_update_node(g->sub_progress_node, 124 stage2_progress_update_node(g->sub_progress_node,
125 g->resolve_queue_index + g->fn_defs_index,125 g->resolve_queue_index + g->fn_defs_index,
126 g->resolve_queue.length + g->fn_defs.length);126 g->resolve_queue.length + g->fn_defs.length);
127}127}
...@@ -1732,7 +1732,7 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) {...@@ -1732,7 +1732,7 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) {
1732ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry) {1732ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry) {
1733 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);1733 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
1734 buf_resize(&err_set_type->name, 0);1734 buf_resize(&err_set_type->name, 0);
1735 buf_appendf(&err_set_type->name, "@typeOf(%s).ReturnType.ErrorSet", buf_ptr(&fn_entry->symbol_name));1735 buf_appendf(&err_set_type->name, "@TypeOf(%s).ReturnType.ErrorSet", buf_ptr(&fn_entry->symbol_name));
1736 err_set_type->data.error_set.err_count = 0;1736 err_set_type->data.error_set.err_count = 0;
1737 err_set_type->data.error_set.errors = nullptr;1737 err_set_type->data.error_set.errors = nullptr;
1738 err_set_type->data.error_set.infer_fn = fn_entry;1738 err_set_type->data.error_set.infer_fn = fn_entry;
src/codegen.cpp+3-3
...@@ -1647,7 +1647,7 @@ static void gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type,...@@ -1647,7 +1647,7 @@ static void gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type,
1647 ptr_type->data.pointer.vector_index, false);1647 ptr_type->data.pointer.vector_index, false);
1648 LLVMValueRef loaded_vector = gen_load(g, ptr, ptr_type, "");1648 LLVMValueRef loaded_vector = gen_load(g, ptr, ptr_type, "");
1649 LLVMValueRef new_vector = LLVMBuildInsertElement(g->builder, loaded_vector, value,1649 LLVMValueRef new_vector = LLVMBuildInsertElement(g->builder, loaded_vector, value,
1650 index_val, ""); 1650 index_val, "");
1651 gen_store(g, new_vector, ptr, ptr_type);1651 gen_store(g, new_vector, ptr, ptr_type);
1652 return;1652 return;
1653 }1653 }
...@@ -8067,7 +8067,7 @@ static void define_builtin_fns(CodeGen *g) {...@@ -8067,7 +8067,7 @@ static void define_builtin_fns(CodeGen *g) {
8067 create_builtin_fn(g, BuiltinFnIdTypeInfo, "typeInfo", 1);8067 create_builtin_fn(g, BuiltinFnIdTypeInfo, "typeInfo", 1);
8068 create_builtin_fn(g, BuiltinFnIdType, "Type", 1);8068 create_builtin_fn(g, BuiltinFnIdType, "Type", 1);
8069 create_builtin_fn(g, BuiltinFnIdHasField, "hasField", 2);8069 create_builtin_fn(g, BuiltinFnIdHasField, "hasField", 2);
8070 create_builtin_fn(g, BuiltinFnIdTypeof, "typeOf", 1); // TODO rename to TypeOf8070 create_builtin_fn(g, BuiltinFnIdTypeof, "TypeOf", 1);
8071 create_builtin_fn(g, BuiltinFnIdAddWithOverflow, "addWithOverflow", 4);8071 create_builtin_fn(g, BuiltinFnIdAddWithOverflow, "addWithOverflow", 4);
8072 create_builtin_fn(g, BuiltinFnIdSubWithOverflow, "subWithOverflow", 4);8072 create_builtin_fn(g, BuiltinFnIdSubWithOverflow, "subWithOverflow", 4);
8073 create_builtin_fn(g, BuiltinFnIdMulWithOverflow, "mulWithOverflow", 4);8073 create_builtin_fn(g, BuiltinFnIdMulWithOverflow, "mulWithOverflow", 4);
...@@ -8407,7 +8407,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -8407,7 +8407,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
8407 break;8407 break;
8408 }8408 }
8409 buf_appendf(contents, "pub const output_mode = OutputMode.%s;\n", out_type);8409 buf_appendf(contents, "pub const output_mode = OutputMode.%s;\n", out_type);
8410 const char *link_type = g->is_dynamic ? "Dynamic" : "Static"; 8410 const char *link_type = g->is_dynamic ? "Dynamic" : "Static";
8411 buf_appendf(contents, "pub const link_mode = LinkMode.%s;\n", link_type);8411 buf_appendf(contents, "pub const link_mode = LinkMode.%s;\n", link_type);
8412 buf_appendf(contents, "pub const is_test = %s;\n", bool_to_str(g->is_test_build));8412 buf_appendf(contents, "pub const is_test = %s;\n", bool_to_str(g->is_test_build));
8413 buf_appendf(contents, "pub const single_threaded = %s;\n", bool_to_str(g->is_single_threaded));8413 buf_appendf(contents, "pub const single_threaded = %s;\n", bool_to_str(g->is_single_threaded));
src/ir.cpp+6-6
...@@ -9267,7 +9267,7 @@ static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) {...@@ -9267,7 +9267,7 @@ static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) {
9267 }9267 }
9268 }9268 }
9269 if (get_scope_typeof(instruction->scope) != nullptr) {9269 if (get_scope_typeof(instruction->scope) != nullptr) {
9270 // doesn't count, it's inside a @typeOf()9270 // doesn't count, it's inside a @TypeOf()
9271 continue;9271 continue;
9272 }9272 }
9273 exec_add_error_node(codegen, exec, instruction->source_node,9273 exec_add_error_node(codegen, exec, instruction->source_node,
...@@ -10413,7 +10413,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -10413,7 +10413,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
10413 return result;10413 return result;
10414 }10414 }
1041510415
10416 bool ok_cv_qualifiers = 10416 bool ok_cv_qualifiers =
10417 (!actual_ptr_type->data.pointer.is_const || wanted_ptr_type->data.pointer.is_const) &&10417 (!actual_ptr_type->data.pointer.is_const || wanted_ptr_type->data.pointer.is_const) &&
10418 (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile);10418 (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile);
10419 if (!ok_cv_qualifiers) {10419 if (!ok_cv_qualifiers) {
...@@ -13779,7 +13779,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13779,7 +13779,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13779 (wanted_type->id == ZigTypeIdOptional && wanted_type->data.maybe.child_type->id == ZigTypeIdEnum))13779 (wanted_type->id == ZigTypeIdOptional && wanted_type->data.maybe.child_type->id == ZigTypeIdEnum))
13780 {13780 {
13781 IrInstruction *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.maybe.child_type);13781 IrInstruction *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.maybe.child_type);
13782 if (result == ira->codegen->invalid_instruction) 13782 if (result == ira->codegen->invalid_instruction)
13783 return result;13783 return result;
1378413784
13785 return ir_analyze_optional_wrap(ira, result, value, wanted_type, nullptr);13785 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...@@ -13790,9 +13790,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13790 (wanted_type->id == ZigTypeIdErrorUnion && wanted_type->data.error_union.payload_type->id == ZigTypeIdEnum))13790 (wanted_type->id == ZigTypeIdErrorUnion && wanted_type->data.error_union.payload_type->id == ZigTypeIdEnum))
13791 {13791 {
13792 IrInstruction *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.error_union.payload_type);13792 IrInstruction *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.error_union.payload_type);
13793 if (result == ira->codegen->invalid_instruction) 13793 if (result == ira->codegen->invalid_instruction)
13794 return result;13794 return result;
13795 13795
13796 return ir_analyze_err_wrap_payload(ira, result, value, wanted_type, nullptr);13796 return ir_analyze_err_wrap_payload(ira, result, value, wanted_type, nullptr);
13797 }13797 }
1379813798
...@@ -19328,7 +19328,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19328,7 +19328,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19328 {19328 {
19329 size_t offset = ptr_field->data.x_ptr.data.base_array.elem_index;19329 size_t offset = ptr_field->data.x_ptr.data.base_array.elem_index;
19330 uint64_t new_index = offset + index;19330 uint64_t new_index = offset + index;
19331 if (ptr_field->data.x_ptr.data.base_array.array_val->data.x_array.special != 19331 if (ptr_field->data.x_ptr.data.base_array.array_val->data.x_array.special !=
19332 ConstArraySpecialBuf)19332 ConstArraySpecialBuf)
19333 {19333 {
19334 ir_assert(new_index <19334 ir_assert(new_index <
src/ir_print.cpp+1-1
...@@ -873,7 +873,7 @@ static void ir_print_vector_store_elem(IrPrint *irp, IrInstructionVectorStoreEle...@@ -873,7 +873,7 @@ static void ir_print_vector_store_elem(IrPrint *irp, IrInstructionVectorStoreEle
873}873}
874874
875static void ir_print_typeof(IrPrint *irp, IrInstructionTypeOf *instruction) {875static void ir_print_typeof(IrPrint *irp, IrInstructionTypeOf *instruction) {
876 fprintf(irp->f, "@typeOf(");876 fprintf(irp->f, "@TypeOf(");
877 ir_print_other_instruction(irp, instruction->value);877 ir_print_other_instruction(irp, instruction->value);
878 fprintf(irp->f, ")");878 fprintf(irp->f, ")");
879}879}
src/translate_c.cpp+4-4
...@@ -4230,7 +4230,7 @@ static AstNode *resolve_typedef_decl(Context *c, const ZigClangTypedefNameDecl *...@@ -4230,7 +4230,7 @@ static AstNode *resolve_typedef_decl(Context *c, const ZigClangTypedefNameDecl *
4230 emit_warning(c, ZigClangTypedefNameDecl_getLocation(typedef_decl),4230 emit_warning(c, ZigClangTypedefNameDecl_getLocation(typedef_decl),
4231 "typedef %s - unresolved child type", buf_ptr(type_name));4231 "typedef %s - unresolved child type", buf_ptr(type_name));
4232 c->decl_table.put(typedef_decl, nullptr);4232 c->decl_table.put(typedef_decl, nullptr);
4233 // TODO add global var with type_name equal to @compileError("unable to resolve C type") 4233 // TODO add global var with type_name equal to @compileError("unable to resolve C type")
4234 return nullptr;4234 return nullptr;
4235 }4235 }
4236 add_global_var(c, type_name, type_node);4236 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...@@ -4919,9 +4919,9 @@ static AstNode *parse_ctok_primary_expr(Context *c, CTokenize *ctok, size_t *tok
4919 *tok_i += 1;4919 *tok_i += 1;
49204920
49214921
4922 //if (@typeId(@typeOf(x)) == @import("builtin").TypeId.Pointer)4922 //if (@typeId(@TypeOf(x)) == @import("builtin").TypeId.Pointer)
4923 // @ptrCast(dest, x)4923 // @ptrCast(dest, x)
4924 //else if (@typeId(@typeOf(x)) == @import("builtin").TypeId.Integer)4924 //else if (@typeId(@TypeOf(x)) == @import("builtin").TypeId.Integer)
4925 // @intToPtr(dest, x)4925 // @intToPtr(dest, x)
4926 //else4926 //else
4927 // (dest)(x)4927 // (dest)(x)
...@@ -4931,7 +4931,7 @@ static AstNode *parse_ctok_primary_expr(Context *c, CTokenize *ctok, size_t *tok...@@ -4931,7 +4931,7 @@ static AstNode *parse_ctok_primary_expr(Context *c, CTokenize *ctok, size_t *tok
4931 AstNode *typeid_type = trans_create_node_field_access_str(c, import_builtin, "TypeId");4931 AstNode *typeid_type = trans_create_node_field_access_str(c, import_builtin, "TypeId");
4932 AstNode *typeid_pointer = trans_create_node_field_access_str(c, typeid_type, "Pointer");4932 AstNode *typeid_pointer = trans_create_node_field_access_str(c, typeid_type, "Pointer");
4933 AstNode *typeid_integer = trans_create_node_field_access_str(c, typeid_type, "Int");4933 AstNode *typeid_integer = trans_create_node_field_access_str(c, typeid_type, "Int");
4934 AstNode *typeof_x = trans_create_node_builtin_fn_call_str(c, "typeOf");4934 AstNode *typeof_x = trans_create_node_builtin_fn_call_str(c, "TypeOf");
4935 typeof_x->data.fn_call_expr.params.append(node_to_cast);4935 typeof_x->data.fn_call_expr.params.append(node_to_cast);
4936 AstNode *typeid_value = trans_create_node_builtin_fn_call_str(c, "typeId");4936 AstNode *typeid_value = trans_create_node_builtin_fn_call_str(c, "typeId");
4937 typeid_value->data.fn_call_expr.params.append(typeof_x);4937 typeid_value->data.fn_call_expr.params.append(typeof_x);
test/compare_output.zig+2-2
...@@ -258,12 +258,12 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -258,12 +258,12 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
258 cases.add("order-independent declarations",258 cases.add("order-independent declarations",
259 \\const io = @import("std").io;259 \\const io = @import("std").io;
260 \\const z = io.stdin_fileno;260 \\const z = io.stdin_fileno;
261 \\const x : @typeOf(y) = 1234;261 \\const x : @TypeOf(y) = 1234;
262 \\const y : u16 = 5678;262 \\const y : u16 = 5678;
263 \\pub fn main() void {263 \\pub fn main() void {
264 \\ var x_local : i32 = print_ok(x);264 \\ var x_local : i32 = print_ok(x);
265 \\}265 \\}
266 \\fn print_ok(val: @typeOf(x)) @typeOf(foo) {266 \\fn print_ok(val: @TypeOf(x)) @TypeOf(foo) {
267 \\ const stdout = &io.getStdOut().outStream().stream;267 \\ const stdout = &io.getStdOut().outStream().stream;
268 \\ stdout.print("OK\n", .{}) catch unreachable;268 \\ stdout.print("OK\n", .{}) catch unreachable;
269 \\ return 0;269 \\ return 0;
test/compile_errors.zig+65-65
...@@ -154,7 +154,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -154,7 +154,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
154 \\ };154 \\ };
155 \\}155 \\}
156 , &[_][]const u8{156 , &[_][]const u8{
157 "tmp.zig:11:25: error: expected type 'u32', found '@typeOf(get_uval).ReturnType.ErrorSet!u32'",157 "tmp.zig:11:25: error: expected type 'u32', found '@TypeOf(get_uval).ReturnType.ErrorSet!u32'",
158 });158 });
159159
160 cases.add("asigning to struct or union fields that are not optionals with a function that returns an optional",160 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 {...@@ -854,7 +854,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
854 cases.add("field access of slices",854 cases.add("field access of slices",
855 \\export fn entry() void {855 \\export fn entry() void {
856 \\ var slice: []i32 = undefined;856 \\ var slice: []i32 = undefined;
857 \\ const info = @typeOf(slice).unknown;857 \\ const info = @TypeOf(slice).unknown;
858 \\}858 \\}
859 , &[_][]const u8{859 , &[_][]const u8{
860 "tmp.zig:3:32: error: type '[]i32' does not support field access",860 "tmp.zig:3:32: error: type '[]i32' does not support field access",
...@@ -894,7 +894,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -894,7 +894,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
894894
895 cases.add("@sizeOf bad type",895 cases.add("@sizeOf bad type",
896 \\export fn entry() usize {896 \\export fn entry() usize {
897 \\ return @sizeOf(@typeOf(null));897 \\ return @sizeOf(@TypeOf(null));
898 \\}898 \\}
899 , &[_][]const u8{899 , &[_][]const u8{
900 "tmp.zig:2:20: error: no size available for type '(null)'",900 "tmp.zig:2:20: error: no size available for type '(null)'",
...@@ -1033,7 +1033,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1033,7 +1033,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
10331033
1034 cases.add("bogus compile var",1034 cases.add("bogus compile var",
1035 \\const x = @import("builtin").bogus;1035 \\const x = @import("builtin").bogus;
1036 \\export fn entry() usize { return @sizeOf(@typeOf(x)); }1036 \\export fn entry() usize { return @sizeOf(@TypeOf(x)); }
1037 , &[_][]const u8{1037 , &[_][]const u8{
1038 "tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'",1038 "tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'",
1039 });1039 });
...@@ -1080,7 +1080,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1080,7 +1080,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1080 \\var foo: Foo = undefined;1080 \\var foo: Foo = undefined;
1081 \\1081 \\
1082 \\export fn entry() usize {1082 \\export fn entry() usize {
1083 \\ return @sizeOf(@typeOf(foo.x));1083 \\ return @sizeOf(@TypeOf(foo.x));
1084 \\}1084 \\}
1085 , &[_][]const u8{1085 , &[_][]const u8{
1086 "tmp.zig:1:13: error: struct 'Foo' depends on itself",1086 "tmp.zig:1:13: error: struct 'Foo' depends on itself",
...@@ -1118,8 +1118,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1118,8 +1118,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1118 });1118 });
11191119
1120 cases.add("top level decl dependency loop",1120 cases.add("top level decl dependency loop",
1121 \\const a : @typeOf(b) = 0;1121 \\const a : @TypeOf(b) = 0;
1122 \\const b : @typeOf(a) = 0;1122 \\const b : @TypeOf(a) = 0;
1123 \\export fn entry() void {1123 \\export fn entry() void {
1124 \\ const c = a + b;1124 \\ const c = a + b;
1125 \\}1125 \\}
...@@ -1620,7 +1620,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1620,7 +1620,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1620 \\var x: f64 = 1.0;1620 \\var x: f64 = 1.0;
1621 \\var y: f32 = x;1621 \\var y: f32 = x;
1622 \\1622 \\
1623 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }1623 \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
1624 , &[_][]const u8{1624 , &[_][]const u8{
1625 "tmp.zig:2:14: error: expected type 'f32', found 'f64'",1625 "tmp.zig:2:14: error: expected type 'f32', found 'f64'",
1626 });1626 });
...@@ -2494,7 +2494,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2494,7 +2494,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2494 \\ }2494 \\ }
2495 \\}2495 \\}
2496 , &[_][]const u8{2496 , &[_][]const u8{
2497 "tmp.zig:5:14: error: duplicate switch value: '@typeOf(foo).ReturnType.ErrorSet.Foo'",2497 "tmp.zig:5:14: error: duplicate switch value: '@TypeOf(foo).ReturnType.ErrorSet.Foo'",
2498 "tmp.zig:3:14: note: other value is here",2498 "tmp.zig:3:14: note: other value is here",
2499 });2499 });
25002500
...@@ -2626,7 +2626,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2626,7 +2626,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2626 \\ try foo();2626 \\ try foo();
2627 \\}2627 \\}
2628 , &[_][]const u8{2628 , &[_][]const u8{
2629 "tmp.zig:5:5: error: cannot resolve inferred error set '@typeOf(foo).ReturnType.ErrorSet': function 'foo' not fully analyzed yet",2629 "tmp.zig:5:5: error: cannot resolve inferred error set '@TypeOf(foo).ReturnType.ErrorSet': function 'foo' not fully analyzed yet",
2630 });2630 });
26312631
2632 cases.add("implicit cast of error set not a subset",2632 cases.add("implicit cast of error set not a subset",
...@@ -3555,7 +3555,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3555,7 +3555,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3555 \\ }3555 \\ }
3556 \\}3556 \\}
3557 \\3557 \\
3558 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }3558 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
3559 , &[_][]const u8{3559 , &[_][]const u8{
3560 "tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch",3560 "tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch",
3561 });3561 });
...@@ -3577,7 +3577,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3577,7 +3577,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3577 \\ }3577 \\ }
3578 \\}3578 \\}
3579 \\3579 \\
3580 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }3580 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
3581 , &[_][]const u8{3581 , &[_][]const u8{
3582 "tmp.zig:13:15: error: duplicate switch value",3582 "tmp.zig:13:15: error: duplicate switch value",
3583 "tmp.zig:10:15: note: other value is here",3583 "tmp.zig:10:15: note: other value is here",
...@@ -3601,7 +3601,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3601,7 +3601,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3601 \\ }3601 \\ }
3602 \\}3602 \\}
3603 \\3603 \\
3604 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }3604 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
3605 , &[_][]const u8{3605 , &[_][]const u8{
3606 "tmp.zig:13:15: error: duplicate switch value",3606 "tmp.zig:13:15: error: duplicate switch value",
3607 "tmp.zig:10:15: note: other value is here",3607 "tmp.zig:10:15: note: other value is here",
...@@ -3628,7 +3628,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3628,7 +3628,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3628 \\ 0 => {},3628 \\ 0 => {},
3629 \\ }3629 \\ }
3630 \\}3630 \\}
3631 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }3631 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
3632 , &[_][]const u8{3632 , &[_][]const u8{
3633 "tmp.zig:2:5: error: switch must handle all possibilities",3633 "tmp.zig:2:5: error: switch must handle all possibilities",
3634 });3634 });
...@@ -3642,7 +3642,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3642,7 +3642,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3642 \\ 206 ... 255 => 3,3642 \\ 206 ... 255 => 3,
3643 \\ };3643 \\ };
3644 \\}3644 \\}
3645 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }3645 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
3646 , &[_][]const u8{3646 , &[_][]const u8{
3647 "tmp.zig:6:9: error: duplicate switch value",3647 "tmp.zig:6:9: error: duplicate switch value",
3648 "tmp.zig:5:14: note: previous value is here",3648 "tmp.zig:5:14: note: previous value is here",
...@@ -3655,7 +3655,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3655,7 +3655,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3655 \\ }3655 \\ }
3656 \\}3656 \\}
3657 \\const y: u8 = 100;3657 \\const y: u8 = 100;
3658 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }3658 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
3659 , &[_][]const u8{3659 , &[_][]const u8{
3660 "tmp.zig:2:5: error: else prong required when switching on type '*u8'",3660 "tmp.zig:2:5: error: else prong required when switching on type '*u8'",
3661 });3661 });
...@@ -3673,7 +3673,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3673,7 +3673,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3673 \\const derp: usize = 1234;3673 \\const derp: usize = 1234;
3674 \\const a = derp ++ "foo";3674 \\const a = derp ++ "foo";
3675 \\3675 \\
3676 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }3676 \\export fn entry() usize { return @sizeOf(@TypeOf(a)); }
3677 , &[_][]const u8{3677 , &[_][]const u8{
3678 "tmp.zig:3:11: error: expected array, found 'usize'",3678 "tmp.zig:3:11: error: expected array, found 'usize'",
3679 });3679 });
...@@ -3683,14 +3683,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3683,14 +3683,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3683 \\ return s ++ "foo";3683 \\ return s ++ "foo";
3684 \\}3684 \\}
3685 \\var s: [10]u8 = undefined;3685 \\var s: [10]u8 = undefined;
3686 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }3686 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
3687 , &[_][]const u8{3687 , &[_][]const u8{
3688 "tmp.zig:2:12: error: unable to evaluate constant expression",3688 "tmp.zig:2:12: error: unable to evaluate constant expression",
3689 });3689 });
36903690
3691 cases.add("@cImport with bogus include",3691 cases.add("@cImport with bogus include",
3692 \\const c = @cImport(@cInclude("bogus.h"));3692 \\const c = @cImport(@cInclude("bogus.h"));
3693 \\export fn entry() usize { return @sizeOf(@typeOf(c.bogo)); }3693 \\export fn entry() usize { return @sizeOf(@TypeOf(c.bogo)); }
3694 , &[_][]const u8{3694 , &[_][]const u8{
3695 "tmp.zig:1:11: error: C import failed",3695 "tmp.zig:1:11: error: C import failed",
3696 ".h:1:10: note: 'bogus.h' file not found",3696 ".h:1:10: note: 'bogus.h' file not found",
...@@ -3700,14 +3700,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3700,14 +3700,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3700 \\const x = 3;3700 \\const x = 3;
3701 \\const y = &x;3701 \\const y = &x;
3702 \\fn foo() *const i32 { return y; }3702 \\fn foo() *const i32 { return y; }
3703 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }3703 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
3704 , &[_][]const u8{3704 , &[_][]const u8{
3705 "tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'",3705 "tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'",
3706 });3706 });
37073707
3708 cases.add("integer overflow error",3708 cases.add("integer overflow error",
3709 \\const x : u8 = 300;3709 \\const x : u8 = 300;
3710 \\export fn entry() usize { return @sizeOf(@typeOf(x)); }3710 \\export fn entry() usize { return @sizeOf(@TypeOf(x)); }
3711 , &[_][]const u8{3711 , &[_][]const u8{
3712 "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'",3712 "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'",
3713 });3713 });
...@@ -3736,7 +3736,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3736,7 +3736,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3736 \\ }3736 \\ }
3737 \\};3737 \\};
3738 \\3738 \\
3739 \\const member_fn_type = @typeOf(Foo.member_a);3739 \\const member_fn_type = @TypeOf(Foo.member_a);
3740 \\const members = [_]member_fn_type {3740 \\const members = [_]member_fn_type {
3741 \\ Foo.member_a,3741 \\ Foo.member_a,
3742 \\ Foo.member_b,3742 \\ Foo.member_b,
...@@ -3746,21 +3746,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3746,21 +3746,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3746 \\ const result = members[index]();3746 \\ const result = members[index]();
3747 \\}3747 \\}
3748 \\3748 \\
3749 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }3749 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
3750 , &[_][]const u8{3750 , &[_][]const u8{
3751 "tmp.zig:20:34: error: expected 1 arguments, found 0",3751 "tmp.zig:20:34: error: expected 1 arguments, found 0",
3752 });3752 });
37533753
3754 cases.add("missing function name",3754 cases.add("missing function name",
3755 \\fn () void {}3755 \\fn () void {}
3756 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }3756 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
3757 , &[_][]const u8{3757 , &[_][]const u8{
3758 "tmp.zig:1:1: error: missing function name",3758 "tmp.zig:1:1: error: missing function name",
3759 });3759 });
37603760
3761 cases.add("missing param name",3761 cases.add("missing param name",
3762 \\fn f(i32) void {}3762 \\fn f(i32) void {}
3763 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }3763 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
3764 , &[_][]const u8{3764 , &[_][]const u8{
3765 "tmp.zig:1:6: error: missing parameter name",3765 "tmp.zig:1:6: error: missing parameter name",
3766 });3766 });
...@@ -3770,7 +3770,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3770,7 +3770,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3770 \\fn a() i32 {return 0;}3770 \\fn a() i32 {return 0;}
3771 \\fn b() i32 {return 1;}3771 \\fn b() i32 {return 1;}
3772 \\fn c() i32 {return 2;}3772 \\fn c() i32 {return 2;}
3773 \\export fn entry() usize { return @sizeOf(@typeOf(fns)); }3773 \\export fn entry() usize { return @sizeOf(@TypeOf(fns)); }
3774 , &[_][]const u8{3774 , &[_][]const u8{
3775 "tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'",3775 "tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'",
3776 });3776 });
...@@ -3781,7 +3781,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3781,7 +3781,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3781 \\pub fn b(x: i32) i32 {return x + 1;}3781 \\pub fn b(x: i32) i32 {return x + 1;}
3782 \\export fn c(x: i32) i32 {return x + 2;}3782 \\export fn c(x: i32) i32 {return x + 2;}
3783 \\3783 \\
3784 \\export fn entry() usize { return @sizeOf(@typeOf(fns)); }3784 \\export fn entry() usize { return @sizeOf(@TypeOf(fns)); }
3785 , &[_][]const u8{3785 , &[_][]const u8{
3786 "tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'extern fn(i32) i32'",3786 "tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'extern fn(i32) i32'",
3787 });3787 });
...@@ -3789,7 +3789,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3789,7 +3789,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3789 cases.add("colliding invalid top level functions",3789 cases.add("colliding invalid top level functions",
3790 \\fn func() bogus {}3790 \\fn func() bogus {}
3791 \\fn func() bogus {}3791 \\fn func() bogus {}
3792 \\export fn entry() usize { return @sizeOf(@typeOf(func)); }3792 \\export fn entry() usize { return @sizeOf(@TypeOf(func)); }
3793 , &[_][]const u8{3793 , &[_][]const u8{
3794 "tmp.zig:2:1: error: redefinition of 'func'",3794 "tmp.zig:2:1: error: redefinition of 'func'",
3795 });3795 });
...@@ -3801,7 +3801,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3801,7 +3801,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3801 \\var global_var: usize = 1;3801 \\var global_var: usize = 1;
3802 \\fn get() usize { return global_var; }3802 \\fn get() usize { return global_var; }
3803 \\3803 \\
3804 \\export fn entry() usize { return @sizeOf(@typeOf(Foo)); }3804 \\export fn entry() usize { return @sizeOf(@TypeOf(Foo)); }
3805 , &[_][]const u8{3805 , &[_][]const u8{
3806 "tmp.zig:5:25: error: unable to evaluate constant expression",3806 "tmp.zig:5:25: error: unable to evaluate constant expression",
3807 "tmp.zig:2:12: note: referenced here",3807 "tmp.zig:2:12: note: referenced here",
...@@ -3813,7 +3813,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3813,7 +3813,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3813 \\};3813 \\};
3814 \\const x = Foo {.field = 1} + Foo {.field = 2};3814 \\const x = Foo {.field = 1} + Foo {.field = 2};
3815 \\3815 \\
3816 \\export fn entry() usize { return @sizeOf(@typeOf(x)); }3816 \\export fn entry() usize { return @sizeOf(@TypeOf(x)); }
3817 , &[_][]const u8{3817 , &[_][]const u8{
3818 "tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'",3818 "tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'",
3819 });3819 });
...@@ -3824,10 +3824,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3824,10 +3824,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3824 \\const int_x = @as(u32, 1) / @as(u32, 0);3824 \\const int_x = @as(u32, 1) / @as(u32, 0);
3825 \\const float_x = @as(f32, 1.0) / @as(f32, 0.0);3825 \\const float_x = @as(f32, 1.0) / @as(f32, 0.0);
3826 \\3826 \\
3827 \\export fn entry1() usize { return @sizeOf(@typeOf(lit_int_x)); }3827 \\export fn entry1() usize { return @sizeOf(@TypeOf(lit_int_x)); }
3828 \\export fn entry2() usize { return @sizeOf(@typeOf(lit_float_x)); }3828 \\export fn entry2() usize { return @sizeOf(@TypeOf(lit_float_x)); }
3829 \\export fn entry3() usize { return @sizeOf(@typeOf(int_x)); }3829 \\export fn entry3() usize { return @sizeOf(@TypeOf(int_x)); }
3830 \\export fn entry4() usize { return @sizeOf(@typeOf(float_x)); }3830 \\export fn entry4() usize { return @sizeOf(@TypeOf(float_x)); }
3831 , &[_][]const u8{3831 , &[_][]const u8{
3832 "tmp.zig:1:21: error: division by zero",3832 "tmp.zig:1:21: error: division by zero",
3833 "tmp.zig:2:25: error: division by zero",3833 "tmp.zig:2:25: error: division by zero",
...@@ -3839,7 +3839,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3839,7 +3839,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3839 \\const foo = "a3839 \\const foo = "a
3840 \\b";3840 \\b";
3841 \\3841 \\
3842 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }3842 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
3843 , &[_][]const u8{3843 , &[_][]const u8{
3844 "tmp.zig:1:15: error: newline not allowed in string literal",3844 "tmp.zig:1:15: error: newline not allowed in string literal",
3845 });3845 });
...@@ -3848,7 +3848,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3848,7 +3848,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3848 \\fn foo() void {}3848 \\fn foo() void {}
3849 \\const invalid = foo > foo;3849 \\const invalid = foo > foo;
3850 \\3850 \\
3851 \\export fn entry() usize { return @sizeOf(@typeOf(invalid)); }3851 \\export fn entry() usize { return @sizeOf(@TypeOf(invalid)); }
3852 , &[_][]const u8{3852 , &[_][]const u8{
3853 "tmp.zig:2:21: error: operator not allowed for type 'fn() void'",3853 "tmp.zig:2:21: error: operator not allowed for type 'fn() void'",
3854 });3854 });
...@@ -3859,7 +3859,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3859,7 +3859,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3859 \\ return foo(a, b);3859 \\ return foo(a, b);
3860 \\}3860 \\}
3861 \\3861 \\
3862 \\export fn entry() usize { return @sizeOf(@typeOf(test1)); }3862 \\export fn entry() usize { return @sizeOf(@TypeOf(test1)); }
3863 , &[_][]const u8{3863 , &[_][]const u8{
3864 "tmp.zig:3:16: error: unable to evaluate constant expression",3864 "tmp.zig:3:16: error: unable to evaluate constant expression",
3865 });3865 });
...@@ -3867,7 +3867,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3867,7 +3867,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3867 cases.add("assign null to non-optional pointer",3867 cases.add("assign null to non-optional pointer",
3868 \\const a: *u8 = null;3868 \\const a: *u8 = null;
3869 \\3869 \\
3870 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }3870 \\export fn entry() usize { return @sizeOf(@TypeOf(a)); }
3871 , &[_][]const u8{3871 , &[_][]const u8{
3872 "tmp.zig:1:16: error: expected type '*u8', found '(null)'",3872 "tmp.zig:1:16: error: expected type '*u8', found '(null)'",
3873 });3873 });
...@@ -3887,7 +3887,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3887,7 +3887,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3887 \\ return 1 / x;3887 \\ return 1 / x;
3888 \\}3888 \\}
3889 \\3889 \\
3890 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }3890 \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
3891 , &[_][]const u8{3891 , &[_][]const u8{
3892 "tmp.zig:3:14: error: division by zero",3892 "tmp.zig:3:14: error: division by zero",
3893 "tmp.zig:1:14: note: referenced here",3893 "tmp.zig:1:14: note: referenced here",
...@@ -3896,7 +3896,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3896,7 +3896,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3896 cases.add("branch on undefined value",3896 cases.add("branch on undefined value",
3897 \\const x = if (undefined) true else false;3897 \\const x = if (undefined) true else false;
3898 \\3898 \\
3899 \\export fn entry() usize { return @sizeOf(@typeOf(x)); }3899 \\export fn entry() usize { return @sizeOf(@TypeOf(x)); }
3900 , &[_][]const u8{3900 , &[_][]const u8{
3901 "tmp.zig:1:15: error: use of undefined value here causes undefined behavior",3901 "tmp.zig:1:15: error: use of undefined value here causes undefined behavior",
3902 });3902 });
...@@ -4276,7 +4276,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4276,7 +4276,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4276 \\ return fibbonaci(x - 1) + fibbonaci(x - 2);4276 \\ return fibbonaci(x - 1) + fibbonaci(x - 2);
4277 \\}4277 \\}
4278 \\4278 \\
4279 \\export fn entry() usize { return @sizeOf(@typeOf(seventh_fib_number)); }4279 \\export fn entry() usize { return @sizeOf(@TypeOf(seventh_fib_number)); }
4280 , &[_][]const u8{4280 , &[_][]const u8{
4281 "tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches",4281 "tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches",
4282 "tmp.zig:1:37: note: referenced here",4282 "tmp.zig:1:37: note: referenced here",
...@@ -4286,7 +4286,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4286,7 +4286,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4286 cases.add("@embedFile with bogus file",4286 cases.add("@embedFile with bogus file",
4287 \\const resource = @embedFile("bogus.txt",);4287 \\const resource = @embedFile("bogus.txt",);
4288 \\4288 \\
4289 \\export fn entry() usize { return @sizeOf(@typeOf(resource)); }4289 \\export fn entry() usize { return @sizeOf(@TypeOf(resource)); }
4290 , &[_][]const u8{4290 , &[_][]const u8{
4291 "tmp.zig:1:29: error: unable to find '",4291 "tmp.zig:1:29: error: unable to find '",
4292 "bogus.txt'",4292 "bogus.txt'",
...@@ -4299,7 +4299,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4299,7 +4299,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4299 \\const a = Foo {.x = get_it()};4299 \\const a = Foo {.x = get_it()};
4300 \\extern fn get_it() i32;4300 \\extern fn get_it() i32;
4301 \\4301 \\
4302 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }4302 \\export fn entry() usize { return @sizeOf(@TypeOf(a)); }
4303 , &[_][]const u8{4303 , &[_][]const u8{
4304 "tmp.zig:4:21: error: unable to evaluate constant expression",4304 "tmp.zig:4:21: error: unable to evaluate constant expression",
4305 });4305 });
...@@ -4315,7 +4315,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4315,7 +4315,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4315 \\}4315 \\}
4316 \\var global_side_effect = false;4316 \\var global_side_effect = false;
4317 \\4317 \\
4318 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }4318 \\export fn entry() usize { return @sizeOf(@TypeOf(a)); }
4319 , &[_][]const u8{4319 , &[_][]const u8{
4320 "tmp.zig:6:26: error: unable to evaluate constant expression",4320 "tmp.zig:6:26: error: unable to evaluate constant expression",
4321 "tmp.zig:4:17: note: referenced here",4321 "tmp.zig:4:17: note: referenced here",
...@@ -4344,8 +4344,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4344,8 +4344,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4344 \\ return a.* == b.*;4344 \\ return a.* == b.*;
4345 \\}4345 \\}
4346 \\4346 \\
4347 \\export fn entry1() usize { return @sizeOf(@typeOf(bad_eql_1)); }4347 \\export fn entry1() usize { return @sizeOf(@TypeOf(bad_eql_1)); }
4348 \\export fn entry2() usize { return @sizeOf(@typeOf(bad_eql_2)); }4348 \\export fn entry2() usize { return @sizeOf(@TypeOf(bad_eql_2)); }
4349 , &[_][]const u8{4349 , &[_][]const u8{
4350 "tmp.zig:2:14: error: operator not allowed for type '[]u8'",4350 "tmp.zig:2:14: error: operator not allowed for type '[]u8'",
4351 "tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'",4351 "tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'",
...@@ -4392,7 +4392,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4392,7 +4392,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4392 \\ return -x;4392 \\ return -x;
4393 \\}4393 \\}
4394 \\4394 \\
4395 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }4395 \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
4396 , &[_][]const u8{4396 , &[_][]const u8{
4397 "tmp.zig:3:12: error: negation caused overflow",4397 "tmp.zig:3:12: error: negation caused overflow",
4398 "tmp.zig:1:14: note: referenced here",4398 "tmp.zig:1:14: note: referenced here",
...@@ -4404,7 +4404,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4404,7 +4404,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4404 \\ return a + b;4404 \\ return a + b;
4405 \\}4405 \\}
4406 \\4406 \\
4407 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }4407 \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
4408 , &[_][]const u8{4408 , &[_][]const u8{
4409 "tmp.zig:3:14: error: operation caused overflow",4409 "tmp.zig:3:14: error: operation caused overflow",
4410 "tmp.zig:1:14: note: referenced here",4410 "tmp.zig:1:14: note: referenced here",
...@@ -4416,7 +4416,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4416,7 +4416,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4416 \\ return a - b;4416 \\ return a - b;
4417 \\}4417 \\}
4418 \\4418 \\
4419 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }4419 \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
4420 , &[_][]const u8{4420 , &[_][]const u8{
4421 "tmp.zig:3:14: error: operation caused overflow",4421 "tmp.zig:3:14: error: operation caused overflow",
4422 "tmp.zig:1:14: note: referenced here",4422 "tmp.zig:1:14: note: referenced here",
...@@ -4428,7 +4428,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4428,7 +4428,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4428 \\ return a * b;4428 \\ return a * b;
4429 \\}4429 \\}
4430 \\4430 \\
4431 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }4431 \\export fn entry() usize { return @sizeOf(@TypeOf(y)); }
4432 , &[_][]const u8{4432 , &[_][]const u8{
4433 "tmp.zig:3:14: error: operation caused overflow",4433 "tmp.zig:3:14: error: operation caused overflow",
4434 "tmp.zig:1:14: note: referenced here",4434 "tmp.zig:1:14: note: referenced here",
...@@ -4440,7 +4440,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4440,7 +4440,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4440 \\ return @truncate(i8, x);4440 \\ return @truncate(i8, x);
4441 \\}4441 \\}
4442 \\4442 \\
4443 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }4443 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
4444 , &[_][]const u8{4444 , &[_][]const u8{
4445 "tmp.zig:3:26: error: expected signed integer type, found 'u32'",4445 "tmp.zig:3:26: error: expected signed integer type, found 'u32'",
4446 });4446 });
...@@ -4480,7 +4480,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4480,7 +4480,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4480 \\fn f() i32 {4480 \\fn f() i32 {
4481 \\ return foo(1, 2);4481 \\ return foo(1, 2);
4482 \\}4482 \\}
4483 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }4483 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
4484 , &[_][]const u8{4484 , &[_][]const u8{
4485 "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'",4485 "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'",
4486 });4486 });
...@@ -4524,7 +4524,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4524,7 +4524,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4524 \\fn f(m: []const u8) void {4524 \\fn f(m: []const u8) void {
4525 \\ m.copy(u8, self[0..], m);4525 \\ m.copy(u8, self[0..], m);
4526 \\}4526 \\}
4527 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }4527 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
4528 , &[_][]const u8{4528 , &[_][]const u8{
4529 "tmp.zig:3:6: error: no member named 'copy' in '[]const u8'",4529 "tmp.zig:3:6: error: no member named 'copy' in '[]const u8'",
4530 });4530 });
...@@ -4537,7 +4537,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4537,7 +4537,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4537 \\4537 \\
4538 \\ foo.method(1, 2);4538 \\ foo.method(1, 2);
4539 \\}4539 \\}
4540 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }4540 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
4541 , &[_][]const u8{4541 , &[_][]const u8{
4542 "tmp.zig:6:15: error: expected 2 arguments, found 3",4542 "tmp.zig:6:15: error: expected 2 arguments, found 3",
4543 });4543 });
...@@ -4596,7 +4596,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4596,7 +4596,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4596 \\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} };4596 \\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} };
4597 \\}4597 \\}
4598 \\4598 \\
4599 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }4599 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
4600 , &[_][]const u8{4600 , &[_][]const u8{
4601 "tmp.zig:5:16: error: use of undeclared identifier 'JsonList'",4601 "tmp.zig:5:16: error: use of undeclared identifier 'JsonList'",
4602 });4602 });
...@@ -4655,7 +4655,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4655,7 +4655,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4655 \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT;4655 \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT;
4656 \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1);4656 \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1);
4657 \\4657 \\
4658 \\export fn entry() usize { return @sizeOf(@typeOf(block_aligned_stuff)); }4658 \\export fn entry() usize { return @sizeOf(@TypeOf(block_aligned_stuff)); }
4659 , &[_][]const u8{4659 , &[_][]const u8{
4660 "tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'",4660 "tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'",
4661 });4661 });
...@@ -4683,7 +4683,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4683,7 +4683,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4683 \\const zero: i32 = 0;4683 \\const zero: i32 = 0;
4684 \\const a = zero{1};4684 \\const a = zero{1};
4685 \\4685 \\
4686 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }4686 \\export fn entry() usize { return @sizeOf(@TypeOf(a)); }
4687 , &[_][]const u8{4687 , &[_][]const u8{
4688 "tmp.zig:2:11: error: expected type 'type', found 'i32'",4688 "tmp.zig:2:11: error: expected type 'type', found 'i32'",
4689 });4689 });
...@@ -4715,7 +4715,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4715,7 +4715,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4715 \\ return 0;4715 \\ return 0;
4716 \\}4716 \\}
4717 \\4717 \\
4718 \\export fn entry() usize { return @sizeOf(@typeOf(testTrickyDefer)); }4718 \\export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); }
4719 , &[_][]const u8{4719 , &[_][]const u8{
4720 "tmp.zig:4:11: error: cannot return from defer expression",4720 "tmp.zig:4:11: error: cannot return from defer expression",
4721 });4721 });
...@@ -4730,7 +4730,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4730,7 +4730,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
47304730
4731 cases.add("global variable alignment non power of 2",4731 cases.add("global variable alignment non power of 2",
4732 \\const some_data: [100]u8 align(3) = undefined;4732 \\const some_data: [100]u8 align(3) = undefined;
4733 \\export fn entry() usize { return @sizeOf(@typeOf(some_data)); }4733 \\export fn entry() usize { return @sizeOf(@TypeOf(some_data)); }
4734 , &[_][]const u8{4734 , &[_][]const u8{
4735 "tmp.zig:1:32: error: alignment value 3 is not a power of 2",4735 "tmp.zig:1:32: error: alignment value 3 is not a power of 2",
4736 });4736 });
...@@ -4772,7 +4772,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4772,7 +4772,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4772 \\ return x.*;4772 \\ return x.*;
4773 \\}4773 \\}
4774 \\4774 \\
4775 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }4775 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
4776 , &[_][]const u8{4776 , &[_][]const u8{
4777 "tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'",4777 "tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'",
4778 });4778 });
...@@ -4875,7 +4875,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4875,7 +4875,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4875 \\ return out.*[0..1];4875 \\ return out.*[0..1];
4876 \\}4876 \\}
4877 \\4877 \\
4878 \\export fn entry() usize { return @sizeOf(@typeOf(pass)); }4878 \\export fn entry() usize { return @sizeOf(@TypeOf(pass)); }
4879 , &[_][]const u8{4879 , &[_][]const u8{
4880 "tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'",4880 "tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'",
4881 });4881 });
...@@ -4890,7 +4890,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4890,7 +4890,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4890 \\ return true;4890 \\ return true;
4891 \\}4891 \\}
4892 \\4892 \\
4893 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }4893 \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
4894 , &[_][]const u8{4894 , &[_][]const u8{
4895 "tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'",4895 "tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'",
4896 });4896 });
...@@ -5726,7 +5726,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5726,7 +5726,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
57265726
5727 cases.add("@ArgType arg index out of bounds",5727 cases.add("@ArgType arg index out of bounds",
5728 \\comptime {5728 \\comptime {
5729 \\ _ = @ArgType(@typeOf(add), 2);5729 \\ _ = @ArgType(@TypeOf(add), 2);
5730 \\}5730 \\}
5731 \\fn add(a: i32, b: i32) i32 { return a + b; }5731 \\fn add(a: i32, b: i32) i32 { return a + b; }
5732 , &[_][]const u8{5732 , &[_][]const u8{
...@@ -6220,7 +6220,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -6220,7 +6220,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
6220 cases.add("getting return type of generic function",6220 cases.add("getting return type of generic function",
6221 \\fn generic(a: var) void {}6221 \\fn generic(a: var) void {}
6222 \\comptime {6222 \\comptime {
6223 \\ _ = @typeOf(generic).ReturnType;6223 \\ _ = @TypeOf(generic).ReturnType;
6224 \\}6224 \\}
6225 , &[_][]const u8{6225 , &[_][]const u8{
6226 "tmp.zig:3:25: error: ReturnType has not been resolved because 'fn(var)var' is generic",6226 "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 {...@@ -6229,7 +6229,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
6229 cases.add("getting @ArgType of generic function",6229 cases.add("getting @ArgType of generic function",
6230 \\fn generic(a: var) void {}6230 \\fn generic(a: var) void {}
6231 \\comptime {6231 \\comptime {
6232 \\ _ = @ArgType(@typeOf(generic), 0);6232 \\ _ = @ArgType(@TypeOf(generic), 0);
6233 \\}6233 \\}
6234 , &[_][]const u8{6234 , &[_][]const u8{
6235 "tmp.zig:3:36: error: @ArgType could not resolve the type of arg 0 because 'fn(var)var' is generic",6235 "tmp.zig:3:36: error: @ArgType could not resolve the type of arg 0 because 'fn(var)var' is generic",
test/stage1/behavior/align.zig+21-21
...@@ -5,10 +5,10 @@ const builtin = @import("builtin");...@@ -5,10 +5,10 @@ const builtin = @import("builtin");
5var foo: u8 align(4) = 100;5var foo: u8 align(4) = 100;
66
7test "global variable alignment" {7test "global variable alignment" {
8 expect(@typeOf(&foo).alignment == 4);8 expect(@TypeOf(&foo).alignment == 4);
9 expect(@typeOf(&foo) == *align(4) u8);9 expect(@TypeOf(&foo) == *align(4) u8);
10 const slice = @as(*[1]u8, &foo)[0..];10 const slice = @as(*[1]u8, &foo)[0..];
11 expect(@typeOf(slice) == []align(4) u8);11 expect(@TypeOf(slice) == []align(4) u8);
12}12}
1313
14fn derp() align(@sizeOf(usize) * 2) i32 {14fn derp() align(@sizeOf(usize) * 2) i32 {
...@@ -19,8 +19,8 @@ fn noop4() align(4) void {}...@@ -19,8 +19,8 @@ fn noop4() align(4) void {}
1919
20test "function alignment" {20test "function alignment" {
21 expect(derp() == 1234);21 expect(derp() == 1234);
22 expect(@typeOf(noop1) == fn () align(1) void);22 expect(@TypeOf(noop1) == fn () align(1) void);
23 expect(@typeOf(noop4) == fn () align(4) void);23 expect(@TypeOf(noop4) == fn () align(4) void);
24 noop1();24 noop1();
25 noop4();25 noop4();
26}26}
...@@ -31,7 +31,7 @@ var baz: packed struct {...@@ -31,7 +31,7 @@ var baz: packed struct {
31} = undefined;31} = undefined;
3232
33test "packed struct alignment" {33test "packed struct alignment" {
34 expect(@typeOf(&baz.b) == *align(1) u32);34 expect(@TypeOf(&baz.b) == *align(1) u32);
35}35}
3636
37const blah: packed struct {37const blah: packed struct {
...@@ -41,7 +41,7 @@ const blah: packed struct {...@@ -41,7 +41,7 @@ const blah: packed struct {
41} = undefined;41} = undefined;
4242
43test "bit field alignment" {43test "bit field alignment" {
44 expect(@typeOf(&blah.b) == *align(1:3:1) const u3);44 expect(@TypeOf(&blah.b) == *align(1:3:1) const u3);
45}45}
4646
47test "default alignment allows unspecified in type syntax" {47test "default alignment allows unspecified in type syntax" {
...@@ -165,28 +165,28 @@ fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {...@@ -165,28 +165,28 @@ fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 {
165test "@ptrCast preserves alignment of bigger source" {165test "@ptrCast preserves alignment of bigger source" {
166 var x: u32 align(16) = 1234;166 var x: u32 align(16) = 1234;
167 const ptr = @ptrCast(*u8, &x);167 const ptr = @ptrCast(*u8, &x);
168 expect(@typeOf(ptr) == *align(16) u8);168 expect(@TypeOf(ptr) == *align(16) u8);
169}169}
170170
171test "runtime known array index has best alignment possible" {171test "runtime known array index has best alignment possible" {
172 // take full advantage of over-alignment172 // take full advantage of over-alignment
173 var array align(4) = [_]u8{ 1, 2, 3, 4 };173 var array align(4) = [_]u8{ 1, 2, 3, 4 };
174 expect(@typeOf(&array[0]) == *align(4) u8);174 expect(@TypeOf(&array[0]) == *align(4) u8);
175 expect(@typeOf(&array[1]) == *u8);175 expect(@TypeOf(&array[1]) == *u8);
176 expect(@typeOf(&array[2]) == *align(2) u8);176 expect(@TypeOf(&array[2]) == *align(2) u8);
177 expect(@typeOf(&array[3]) == *u8);177 expect(@TypeOf(&array[3]) == *u8);
178178
179 // because align is too small but we still figure out to use 2179 // because align is too small but we still figure out to use 2
180 var bigger align(2) = [_]u64{ 1, 2, 3, 4 };180 var bigger align(2) = [_]u64{ 1, 2, 3, 4 };
181 expect(@typeOf(&bigger[0]) == *align(2) u64);181 expect(@TypeOf(&bigger[0]) == *align(2) u64);
182 expect(@typeOf(&bigger[1]) == *align(2) u64);182 expect(@TypeOf(&bigger[1]) == *align(2) u64);
183 expect(@typeOf(&bigger[2]) == *align(2) u64);183 expect(@TypeOf(&bigger[2]) == *align(2) u64);
184 expect(@typeOf(&bigger[3]) == *align(2) u64);184 expect(@TypeOf(&bigger[3]) == *align(2) u64);
185185
186 // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2186 // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2
187 var smaller align(2) = [_]u32{ 1, 2, 3, 4 };187 var smaller align(2) = [_]u32{ 1, 2, 3, 4 };
188 comptime expect(@typeOf(smaller[0..]) == []align(2) u32);188 comptime expect(@TypeOf(smaller[0..]) == []align(2) u32);
189 comptime expect(@typeOf(smaller[0..].ptr) == [*]align(2) u32);189 comptime expect(@TypeOf(smaller[0..].ptr) == [*]align(2) u32);
190 testIndex(smaller[0..].ptr, 0, *align(2) u32);190 testIndex(smaller[0..].ptr, 0, *align(2) u32);
191 testIndex(smaller[0..].ptr, 1, *align(2) u32);191 testIndex(smaller[0..].ptr, 1, *align(2) u32);
192 testIndex(smaller[0..].ptr, 2, *align(2) u32);192 testIndex(smaller[0..].ptr, 2, *align(2) u32);
...@@ -199,10 +199,10 @@ test "runtime known array index has best alignment possible" {...@@ -199,10 +199,10 @@ test "runtime known array index has best alignment possible" {
199 testIndex2(array[0..].ptr, 3, *u8);199 testIndex2(array[0..].ptr, 3, *u8);
200}200}
201fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) void {201fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) void {
202 comptime expect(@typeOf(&smaller[index]) == T);202 comptime expect(@TypeOf(&smaller[index]) == T);
203}203}
204fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) void {204fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) void {
205 comptime expect(@typeOf(&ptr[index]) == T);205 comptime expect(@TypeOf(&ptr[index]) == T);
206}206}
207207
208test "alignstack" {208test "alignstack" {
...@@ -303,7 +303,7 @@ test "struct field explicit alignment" {...@@ -303,7 +303,7 @@ test "struct field explicit alignment" {
303 var node: S.Node = undefined;303 var node: S.Node = undefined;
304 node.massive_byte = 100;304 node.massive_byte = 100;
305 expect(node.massive_byte == 100);305 expect(node.massive_byte == 100);
306 comptime expect(@typeOf(&node.massive_byte) == *align(64) u8);306 comptime expect(@TypeOf(&node.massive_byte) == *align(64) u8);
307 expect(@ptrToInt(&node.massive_byte) % 64 == 0);307 expect(@ptrToInt(&node.massive_byte) % 64 == 0);
308}308}
309309
test/stage1/behavior/array.zig+3-3
...@@ -30,7 +30,7 @@ test "void arrays" {...@@ -30,7 +30,7 @@ test "void arrays" {
30 var array: [4]void = undefined;30 var array: [4]void = undefined;
31 array[0] = void{};31 array[0] = void{};
32 array[1] = array[2];32 array[1] = array[2];
33 expect(@sizeOf(@typeOf(array)) == 0);33 expect(@sizeOf(@TypeOf(array)) == 0);
34 expect(array.len == 4);34 expect(array.len == 4);
35}35}
3636
...@@ -109,12 +109,12 @@ test "array literal with specified size" {...@@ -109,12 +109,12 @@ test "array literal with specified size" {
109109
110test "array child property" {110test "array child property" {
111 var x: [5]i32 = undefined;111 var x: [5]i32 = undefined;
112 expect(@typeOf(x).Child == i32);112 expect(@TypeOf(x).Child == i32);
113}113}
114114
115test "array len property" {115test "array len property" {
116 var x: [5]i32 = undefined;116 var x: [5]i32 = undefined;
117 expect(@typeOf(x).len == 5);117 expect(@TypeOf(x).len == 5);
118}118}
119119
120test "array len field" {120test "array len field" {
test/stage1/behavior/async_fn.zig+12-12
...@@ -185,7 +185,7 @@ var a_promise: anyframe = undefined;...@@ -185,7 +185,7 @@ var a_promise: anyframe = undefined;
185var global_result = false;185var global_result = false;
186async fn testSuspendBlock() void {186async fn testSuspendBlock() void {
187 suspend {187 suspend {
188 comptime expect(@typeOf(@frame()) == *@Frame(testSuspendBlock));188 comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock));
189 a_promise = @frame();189 a_promise = @frame();
190 }190 }
191191
...@@ -282,7 +282,7 @@ test "async fn pointer in a struct field" {...@@ -282,7 +282,7 @@ test "async fn pointer in a struct field" {
282 var foo = Foo{ .bar = simpleAsyncFn2 };282 var foo = Foo{ .bar = simpleAsyncFn2 };
283 var bytes: [64]u8 align(16) = undefined;283 var bytes: [64]u8 align(16) = undefined;
284 const f = @asyncCall(&bytes, {}, foo.bar, &data);284 const f = @asyncCall(&bytes, {}, foo.bar, &data);
285 comptime expect(@typeOf(f) == anyframe->void);285 comptime expect(@TypeOf(f) == anyframe->void);
286 expect(data == 2);286 expect(data == 2);
287 resume f;287 resume f;
288 expect(data == 4);288 expect(data == 4);
...@@ -332,7 +332,7 @@ test "async fn with inferred error set" {...@@ -332,7 +332,7 @@ test "async fn with inferred error set" {
332 fn doTheTest() void {332 fn doTheTest() void {
333 var frame: [1]@Frame(middle) = undefined;333 var frame: [1]@Frame(middle) = undefined;
334 var fn_ptr = middle;334 var fn_ptr = middle;
335 var result: @typeOf(fn_ptr).ReturnType.ErrorSet!void = undefined;335 var result: @TypeOf(fn_ptr).ReturnType.ErrorSet!void = undefined;
336 _ = @asyncCall(@sliceToBytes(frame[0..]), &result, fn_ptr);336 _ = @asyncCall(@sliceToBytes(frame[0..]), &result, fn_ptr);
337 resume global_frame;337 resume global_frame;
338 std.testing.expectError(error.Fail, result);338 std.testing.expectError(error.Fail, result);
...@@ -952,7 +952,7 @@ test "@asyncCall with comptime-known function, but not awaited directly" {...@@ -952,7 +952,7 @@ test "@asyncCall with comptime-known function, but not awaited directly" {
952952
953 fn doTheTest() void {953 fn doTheTest() void {
954 var frame: [1]@Frame(middle) = undefined;954 var frame: [1]@Frame(middle) = undefined;
955 var result: @typeOf(middle).ReturnType.ErrorSet!void = undefined;955 var result: @TypeOf(middle).ReturnType.ErrorSet!void = undefined;
956 _ = @asyncCall(@sliceToBytes(frame[0..]), &result, middle);956 _ = @asyncCall(@sliceToBytes(frame[0..]), &result, middle);
957 resume global_frame;957 resume global_frame;
958 std.testing.expectError(error.Fail, result);958 std.testing.expectError(error.Fail, result);
...@@ -1009,7 +1009,7 @@ test "@asyncCall using the result location inside the frame" {...@@ -1009,7 +1009,7 @@ test "@asyncCall using the result location inside the frame" {
1009 var foo = Foo{ .bar = S.simple2 };1009 var foo = Foo{ .bar = S.simple2 };
1010 var bytes: [64]u8 align(16) = undefined;1010 var bytes: [64]u8 align(16) = undefined;
1011 const f = @asyncCall(&bytes, {}, foo.bar, &data);1011 const f = @asyncCall(&bytes, {}, foo.bar, &data);
1012 comptime expect(@typeOf(f) == anyframe->i32);1012 comptime expect(@TypeOf(f) == anyframe->i32);
1013 expect(data == 2);1013 expect(data == 2);
1014 resume f;1014 resume f;
1015 expect(data == 4);1015 expect(data == 4);
...@@ -1017,18 +1017,18 @@ test "@asyncCall using the result location inside the frame" {...@@ -1017,18 +1017,18 @@ test "@asyncCall using the result location inside the frame" {
1017 expect(data == 1234);1017 expect(data == 1234);
1018}1018}
10191019
1020test "@typeOf an async function call of generic fn with error union type" {1020test "@TypeOf an async function call of generic fn with error union type" {
1021 const S = struct {1021 const S = struct {
1022 fn func(comptime x: var) anyerror!i32 {1022 fn func(comptime x: var) anyerror!i32 {
1023 const T = @typeOf(async func(x));1023 const T = @TypeOf(async func(x));
1024 comptime expect(T == @typeOf(@frame()).Child);1024 comptime expect(T == @TypeOf(@frame()).Child);
1025 return undefined;1025 return undefined;
1026 }1026 }
1027 };1027 };
1028 _ = async S.func(i32);1028 _ = async S.func(i32);
1029}1029}
10301030
1031test "using @typeOf on a generic function call" {1031test "using @TypeOf on a generic function call" {
1032 const S = struct {1032 const S = struct {
1033 var global_frame: anyframe = undefined;1033 var global_frame: anyframe = undefined;
1034 var global_ok = false;1034 var global_ok = false;
...@@ -1043,7 +1043,7 @@ test "using @typeOf on a generic function call" {...@@ -1043,7 +1043,7 @@ test "using @typeOf on a generic function call" {
1043 suspend {1043 suspend {
1044 global_frame = @frame();1044 global_frame = @frame();
1045 }1045 }
1046 const F = @typeOf(async amain(x - 1));1046 const F = @TypeOf(async amain(x - 1));
1047 const frame = @intToPtr(*F, @ptrToInt(&buf));1047 const frame = @intToPtr(*F, @ptrToInt(&buf));
1048 return await @asyncCall(frame, {}, amain, x - 1);1048 return await @asyncCall(frame, {}, amain, x - 1);
1049 }1049 }
...@@ -1068,7 +1068,7 @@ test "recursive call of await @asyncCall with struct return type" {...@@ -1068,7 +1068,7 @@ test "recursive call of await @asyncCall with struct return type" {
1068 suspend {1068 suspend {
1069 global_frame = @frame();1069 global_frame = @frame();
1070 }1070 }
1071 const F = @typeOf(async amain(x - 1));1071 const F = @TypeOf(async amain(x - 1));
1072 const frame = @intToPtr(*F, @ptrToInt(&buf));1072 const frame = @intToPtr(*F, @ptrToInt(&buf));
1073 return await @asyncCall(frame, {}, amain, x - 1);1073 return await @asyncCall(frame, {}, amain, x - 1);
1074 }1074 }
...@@ -1080,7 +1080,7 @@ test "recursive call of await @asyncCall with struct return type" {...@@ -1080,7 +1080,7 @@ test "recursive call of await @asyncCall with struct return type" {
1080 };1080 };
1081 };1081 };
1082 var res: S.Foo = undefined;1082 var res: S.Foo = undefined;
1083 var frame: @typeOf(async S.amain(@as(u32, 1))) = undefined;1083 var frame: @TypeOf(async S.amain(@as(u32, 1))) = undefined;
1084 _ = @asyncCall(&frame, &res, S.amain, @as(u32, 1));1084 _ = @asyncCall(&frame, &res, S.amain, @as(u32, 1));
1085 resume S.global_frame;1085 resume S.global_frame;
1086 expect(S.global_ok);1086 expect(S.global_ok);
test/stage1/behavior/atomics.zig+2-2
...@@ -118,7 +118,7 @@ test "atomic load and rmw with enum" {...@@ -118,7 +118,7 @@ test "atomic load and rmw with enum" {
118118
119 expect(@atomicLoad(Value, &x, .SeqCst) != .b);119 expect(@atomicLoad(Value, &x, .SeqCst) != .b);
120120
121 _ = @atomicRmw(Value, &x, .Xchg, .c, .SeqCst); 121 _ = @atomicRmw(Value, &x, .Xchg, .c, .SeqCst);
122 expect(@atomicLoad(Value, &x, .SeqCst) == .c);122 expect(@atomicLoad(Value, &x, .SeqCst) == .c);
123 expect(@atomicLoad(Value, &x, .SeqCst) != .a);123 expect(@atomicLoad(Value, &x, .SeqCst) != .a);
124 expect(@atomicLoad(Value, &x, .SeqCst) != .b);124 expect(@atomicLoad(Value, &x, .SeqCst) != .b);
...@@ -143,4 +143,4 @@ fn testAtomicStore() void {...@@ -143,4 +143,4 @@ fn testAtomicStore() void {
143 expect(@atomicLoad(u32, &x, .SeqCst) == 1);143 expect(@atomicLoad(u32, &x, .SeqCst) == 1);
144 @atomicStore(u32, &x, 12345678, .SeqCst);144 @atomicStore(u32, &x, 12345678, .SeqCst);
145 expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);145 expect(@atomicLoad(u32, &x, .SeqCst) == 12345678);
146}
\ No newline at end of file
146}
test/stage1/behavior/bugs/1851.zig+1-1
...@@ -15,7 +15,7 @@ test "allocation and looping over 3-byte integer" {...@@ -15,7 +15,7 @@ test "allocation and looping over 3-byte integer" {
15 x[1] = 0xFFFFFF;15 x[1] = 0xFFFFFF;
1616
17 const bytes = @sliceToBytes(x);17 const bytes = @sliceToBytes(x);
18 expect(@typeOf(bytes) == []align(4) u8);18 expect(@TypeOf(bytes) == []align(4) u8);
19 expect(bytes.len == 8);19 expect(bytes.len == 8);
2020
21 for (bytes) |*b| {21 for (bytes) |*b| {
test/stage1/behavior/bugs/2114.zig+1-1
...@@ -3,7 +3,7 @@ const expect = std.testing.expect;...@@ -3,7 +3,7 @@ const expect = std.testing.expect;
3const math = std.math;3const math = std.math;
44
5fn ctz(x: var) usize {5fn ctz(x: var) usize {
6 return @ctz(@typeOf(x), x);6 return @ctz(@TypeOf(x), x);
7}7}
88
9test "fixed" {9test "fixed" {
test/stage1/behavior/bugs/3742.zig+1-1
...@@ -24,7 +24,7 @@ pub fn isCommand(comptime T: type) bool {...@@ -24,7 +24,7 @@ pub fn isCommand(comptime T: type) bool {
2424
25pub const ArgSerializer = struct {25pub const ArgSerializer = struct {
26 pub fn serializeCommand(command: var) void {26 pub fn serializeCommand(command: var) void {
27 const CmdT = @typeOf(command);27 const CmdT = @TypeOf(command);
2828
29 if (comptime isCommand(CmdT)) {29 if (comptime isCommand(CmdT)) {
30 // COMMENTING THE NEXT LINE REMOVES THE ERROR30 // COMMENTING THE NEXT LINE REMOVES THE ERROR
test/stage1/behavior/bugs/655.zig+1-1
...@@ -3,7 +3,7 @@ const other_file = @import("655_other_file.zig");...@@ -3,7 +3,7 @@ const other_file = @import("655_other_file.zig");
33
4test "function with *const parameter with type dereferenced by namespace" {4test "function with *const parameter with type dereferenced by namespace" {
5 const x: other_file.Integer = 1234;5 const x: other_file.Integer = 1234;
6 comptime std.testing.expect(@typeOf(&x) == *const other_file.Integer);6 comptime std.testing.expect(@TypeOf(&x) == *const other_file.Integer);
7 foo(&x);7 foo(&x);
8}8}
99
test/stage1/behavior/bugs/718.zig+1-1
...@@ -9,7 +9,7 @@ const Keys = struct {...@@ -9,7 +9,7 @@ const Keys = struct {
9};9};
10var keys: Keys = undefined;10var keys: Keys = undefined;
11test "zero keys with @memset" {11test "zero keys with @memset" {
12 @memset(@ptrCast([*]u8, &keys), 0, @sizeOf(@typeOf(keys)));12 @memset(@ptrCast([*]u8, &keys), 0, @sizeOf(@TypeOf(keys)));
13 expect(!keys.up);13 expect(!keys.up);
14 expect(!keys.down);14 expect(!keys.down);
15 expect(!keys.left);15 expect(!keys.left);
test/stage1/behavior/cast.zig+10-10
...@@ -226,14 +226,14 @@ fn testCastConstArrayRefToConstSlice() void {...@@ -226,14 +226,14 @@ fn testCastConstArrayRefToConstSlice() void {
226 {226 {
227 const blah = "aoeu".*;227 const blah = "aoeu".*;
228 const const_array_ref = &blah;228 const const_array_ref = &blah;
229 expect(@typeOf(const_array_ref) == *const [4:0]u8);229 expect(@TypeOf(const_array_ref) == *const [4:0]u8);
230 const slice: []const u8 = const_array_ref;230 const slice: []const u8 = const_array_ref;
231 expect(mem.eql(u8, slice, "aoeu"));231 expect(mem.eql(u8, slice, "aoeu"));
232 }232 }
233 {233 {
234 const blah: [4]u8 = "aoeu".*;234 const blah: [4]u8 = "aoeu".*;
235 const const_array_ref = &blah;235 const const_array_ref = &blah;
236 expect(@typeOf(const_array_ref) == *const [4]u8);236 expect(@TypeOf(const_array_ref) == *const [4]u8);
237 const slice: []const u8 = const_array_ref;237 const slice: []const u8 = const_array_ref;
238 expect(mem.eql(u8, slice, "aoeu"));238 expect(mem.eql(u8, slice, "aoeu"));
239 }239 }
...@@ -353,29 +353,29 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" {...@@ -353,29 +353,29 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
353353
354test "@intCast comptime_int" {354test "@intCast comptime_int" {
355 const result = @intCast(i32, 1234);355 const result = @intCast(i32, 1234);
356 expect(@typeOf(result) == i32);356 expect(@TypeOf(result) == i32);
357 expect(result == 1234);357 expect(result == 1234);
358}358}
359359
360test "@floatCast comptime_int and comptime_float" {360test "@floatCast comptime_int and comptime_float" {
361 {361 {
362 const result = @floatCast(f16, 1234);362 const result = @floatCast(f16, 1234);
363 expect(@typeOf(result) == f16);363 expect(@TypeOf(result) == f16);
364 expect(result == 1234.0);364 expect(result == 1234.0);
365 }365 }
366 {366 {
367 const result = @floatCast(f16, 1234.0);367 const result = @floatCast(f16, 1234.0);
368 expect(@typeOf(result) == f16);368 expect(@TypeOf(result) == f16);
369 expect(result == 1234.0);369 expect(result == 1234.0);
370 }370 }
371 {371 {
372 const result = @floatCast(f32, 1234);372 const result = @floatCast(f32, 1234);
373 expect(@typeOf(result) == f32);373 expect(@TypeOf(result) == f32);
374 expect(result == 1234.0);374 expect(result == 1234.0);
375 }375 }
376 {376 {
377 const result = @floatCast(f32, 1234.0);377 const result = @floatCast(f32, 1234.0);
378 expect(@typeOf(result) == f32);378 expect(@TypeOf(result) == f32);
379 expect(result == 1234.0);379 expect(result == 1234.0);
380 }380 }
381}381}
...@@ -383,12 +383,12 @@ test "@floatCast comptime_int and comptime_float" {...@@ -383,12 +383,12 @@ test "@floatCast comptime_int and comptime_float" {
383test "comptime_int @intToFloat" {383test "comptime_int @intToFloat" {
384 {384 {
385 const result = @intToFloat(f16, 1234);385 const result = @intToFloat(f16, 1234);
386 expect(@typeOf(result) == f16);386 expect(@TypeOf(result) == f16);
387 expect(result == 1234.0);387 expect(result == 1234.0);
388 }388 }
389 {389 {
390 const result = @intToFloat(f32, 1234);390 const result = @intToFloat(f32, 1234);
391 expect(@typeOf(result) == f32);391 expect(@TypeOf(result) == f32);
392 expect(result == 1234.0);392 expect(result == 1234.0);
393 }393 }
394}394}
...@@ -396,7 +396,7 @@ test "comptime_int @intToFloat" {...@@ -396,7 +396,7 @@ test "comptime_int @intToFloat" {
396test "@bytesToSlice keeps pointer alignment" {396test "@bytesToSlice keeps pointer alignment" {
397 var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };397 var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 };
398 const numbers = @bytesToSlice(u32, bytes[0..]);398 const numbers = @bytesToSlice(u32, bytes[0..]);
399 comptime expect(@typeOf(numbers) == []align(@alignOf(@typeOf(bytes))) u32);399 comptime expect(@TypeOf(numbers) == []align(@alignOf(@TypeOf(bytes))) u32);
400}400}
401401
402test "@intCast i32 to u7" {402test "@intCast i32 to u7" {
test/stage1/behavior/error.zig+3-3
...@@ -83,9 +83,9 @@ test "error union type " {...@@ -83,9 +83,9 @@ test "error union type " {
83fn testErrorUnionType() void {83fn testErrorUnionType() void {
84 const x: anyerror!i32 = 1234;84 const x: anyerror!i32 = 1234;
85 if (x) |value| expect(value == 1234) else |_| unreachable;85 if (x) |value| expect(value == 1234) else |_| unreachable;
86 expect(@typeId(@typeOf(x)) == builtin.TypeId.ErrorUnion);86 expect(@typeId(@TypeOf(x)) == builtin.TypeId.ErrorUnion);
87 expect(@typeId(@typeOf(x).ErrorSet) == builtin.TypeId.ErrorSet);87 expect(@typeId(@TypeOf(x).ErrorSet) == builtin.TypeId.ErrorSet);
88 expect(@typeOf(x).ErrorSet == anyerror);88 expect(@TypeOf(x).ErrorSet == anyerror);
89}89}
9090
91test "error set type" {91test "error set type" {
test/stage1/behavior/eval.zig+2-2
...@@ -105,7 +105,7 @@ pub fn vec3(x: f32, y: f32, z: f32) Vec3 {...@@ -105,7 +105,7 @@ pub fn vec3(x: f32, y: f32, z: f32) Vec3 {
105105
106test "constant expressions" {106test "constant expressions" {
107 var array: [array_size]u8 = undefined;107 var array: [array_size]u8 = undefined;
108 expect(@sizeOf(@typeOf(array)) == 20);108 expect(@sizeOf(@TypeOf(array)) == 20);
109}109}
110const array_size: u8 = 20;110const array_size: u8 = 20;
111111
...@@ -598,7 +598,7 @@ test "pointer to type" {...@@ -598,7 +598,7 @@ test "pointer to type" {
598 var T: type = i32;598 var T: type = i32;
599 expect(T == i32);599 expect(T == i32);
600 var ptr = &T;600 var ptr = &T;
601 expect(@typeOf(ptr) == *type);601 expect(@TypeOf(ptr) == *type);
602 ptr.* = f32;602 ptr.* = f32;
603 expect(T == f32);603 expect(T == f32);
604 expect(*T == *f32);604 expect(*T == *f32);
test/stage1/behavior/fn.zig+4-4
...@@ -73,7 +73,7 @@ fn fnWithUnreachable() noreturn {...@@ -73,7 +73,7 @@ fn fnWithUnreachable() noreturn {
73}73}
7474
75test "function pointers" {75test "function pointers" {
76 const fns = [_]@typeOf(fn1){76 const fns = [_]@TypeOf(fn1){
77 fn1,77 fn1,
78 fn2,78 fn2,
79 fn3,79 fn3,
...@@ -130,7 +130,7 @@ test "pass by non-copying value through var arg" {...@@ -130,7 +130,7 @@ test "pass by non-copying value through var arg" {
130}130}
131131
132fn addPointCoordsVar(pt: var) i32 {132fn addPointCoordsVar(pt: var) i32 {
133 comptime expect(@typeOf(pt) == Point);133 comptime expect(@TypeOf(pt) == Point);
134 return pt.x + pt.y;134 return pt.x + pt.y;
135}135}
136136
...@@ -170,7 +170,7 @@ test "pass by non-copying value as method, at comptime" {...@@ -170,7 +170,7 @@ test "pass by non-copying value as method, at comptime" {
170}170}
171171
172fn outer(y: u32) fn (u32) u32 {172fn outer(y: u32) fn (u32) u32 {
173 const Y = @typeOf(y);173 const Y = @TypeOf(y);
174 const st = struct {174 const st = struct {
175 fn get(z: u32) u32 {175 fn get(z: u32) u32 {
176 return z + @sizeOf(Y);176 return z + @sizeOf(Y);
...@@ -265,7 +265,7 @@ test "ability to give comptime types and non comptime types to same parameter" {...@@ -265,7 +265,7 @@ test "ability to give comptime types and non comptime types to same parameter" {
265 }265 }
266266
267 fn foo(arg: var) i32 {267 fn foo(arg: var) i32 {
268 if (@typeInfo(@typeOf(arg)) == .Type and arg == i32) return 20;268 if (@typeInfo(@TypeOf(arg)) == .Type and arg == i32) return 20;
269 return 9 + arg;269 return 9 + arg;
270 }270 }
271 };271 };
test/stage1/behavior/for.zig+2-2
...@@ -29,9 +29,9 @@ test "for loop with pointer elem var" {...@@ -29,9 +29,9 @@ test "for loop with pointer elem var" {
29 expect(mem.eql(u8, &target, "bcdefgh"));29 expect(mem.eql(u8, &target, "bcdefgh"));
3030
31 for (source) |*c, i|31 for (source) |*c, i|
32 expect(@typeOf(c) == *const u8);32 expect(@TypeOf(c) == *const u8);
33 for (target) |*c, i|33 for (target) |*c, i|
34 expect(@typeOf(c) == *u8);34 expect(@TypeOf(c) == *u8);
35}35}
3636
37fn mangleString(s: []u8) void {37fn mangleString(s: []u8) void {
test/stage1/behavior/generics.zig+1-1
...@@ -47,7 +47,7 @@ comptime {...@@ -47,7 +47,7 @@ comptime {
47 expect(max_f64(1.2, 3.4) == 3.4);47 expect(max_f64(1.2, 3.4) == 3.4);
48}48}
4949
50fn max_var(a: var, b: var) @typeOf(a + b) {50fn max_var(a: var, b: var) @TypeOf(a + b) {
51 return if (a > b) a else b;51 return if (a > b) a else b;
52}52}
5353
test/stage1/behavior/math.zig+3-3
...@@ -281,8 +281,8 @@ test "small int addition" {...@@ -281,8 +281,8 @@ test "small int addition" {
281 x += 1;281 x += 1;
282 expect(x == 3);282 expect(x == 3);
283283
284 var result: @typeOf(x) = 3;284 var result: @TypeOf(x) = 3;
285 expect(@addWithOverflow(@typeOf(x), x, 1, &result));285 expect(@addWithOverflow(@TypeOf(x), x, 1, &result));
286286
287 expect(result == 0);287 expect(result == 0);
288}288}
...@@ -586,7 +586,7 @@ test "@sqrt" {...@@ -586,7 +586,7 @@ test "@sqrt" {
586586
587 const x = 14.0;587 const x = 14.0;
588 const y = x * x;588 const y = x * x;
589 const z = @sqrt(@typeOf(y), y);589 const z = @sqrt(@TypeOf(y), y);
590 comptime expect(z == x);590 comptime expect(z == x);
591}591}
592592
test/stage1/behavior/misc.zig+10-10
...@@ -362,8 +362,8 @@ test "string concatenation" {...@@ -362,8 +362,8 @@ test "string concatenation" {
362 const a = "OK" ++ " IT " ++ "WORKED";362 const a = "OK" ++ " IT " ++ "WORKED";
363 const b = "OK IT WORKED";363 const b = "OK IT WORKED";
364364
365 comptime expect(@typeOf(a) == *const [12:0]u8);365 comptime expect(@TypeOf(a) == *const [12:0]u8);
366 comptime expect(@typeOf(b) == *const [12:0]u8);366 comptime expect(@TypeOf(b) == *const [12:0]u8);
367367
368 const len = mem.len(u8, b);368 const len = mem.len(u8, b);
369 const len_with_null = len + 1;369 const len_with_null = len + 1;
...@@ -460,19 +460,19 @@ test "@typeId" {...@@ -460,19 +460,19 @@ test "@typeId" {
460 expect(@typeId(*f32) == Tid.Pointer);460 expect(@typeId(*f32) == Tid.Pointer);
461 expect(@typeId([2]u8) == Tid.Array);461 expect(@typeId([2]u8) == Tid.Array);
462 expect(@typeId(AStruct) == Tid.Struct);462 expect(@typeId(AStruct) == Tid.Struct);
463 expect(@typeId(@typeOf(1)) == Tid.ComptimeInt);463 expect(@typeId(@TypeOf(1)) == Tid.ComptimeInt);
464 expect(@typeId(@typeOf(1.0)) == Tid.ComptimeFloat);464 expect(@typeId(@TypeOf(1.0)) == Tid.ComptimeFloat);
465 expect(@typeId(@typeOf(undefined)) == Tid.Undefined);465 expect(@typeId(@TypeOf(undefined)) == Tid.Undefined);
466 expect(@typeId(@typeOf(null)) == Tid.Null);466 expect(@typeId(@TypeOf(null)) == Tid.Null);
467 expect(@typeId(?i32) == Tid.Optional);467 expect(@typeId(?i32) == Tid.Optional);
468 expect(@typeId(anyerror!i32) == Tid.ErrorUnion);468 expect(@typeId(anyerror!i32) == Tid.ErrorUnion);
469 expect(@typeId(anyerror) == Tid.ErrorSet);469 expect(@typeId(anyerror) == Tid.ErrorSet);
470 expect(@typeId(AnEnum) == Tid.Enum);470 expect(@typeId(AnEnum) == Tid.Enum);
471 expect(@typeId(@typeOf(AUnionEnum.One)) == Tid.Enum);471 expect(@typeId(@TypeOf(AUnionEnum.One)) == Tid.Enum);
472 expect(@typeId(AUnionEnum) == Tid.Union);472 expect(@typeId(AUnionEnum) == Tid.Union);
473 expect(@typeId(AUnion) == Tid.Union);473 expect(@typeId(AUnion) == Tid.Union);
474 expect(@typeId(fn () void) == Tid.Fn);474 expect(@typeId(fn () void) == Tid.Fn);
475 expect(@typeId(@typeOf(builtin)) == Tid.Type);475 expect(@typeId(@TypeOf(builtin)) == Tid.Type);
476 // TODO bound fn476 // TODO bound fn
477 // TODO arg tuple477 // TODO arg tuple
478 // TODO opaque478 // TODO opaque
...@@ -652,9 +652,9 @@ test "volatile load and store" {...@@ -652,9 +652,9 @@ test "volatile load and store" {
652652
653test "slice string literal has type []const u8" {653test "slice string literal has type []const u8" {
654 comptime {654 comptime {
655 expect(@typeOf("aoeu"[0..]) == []const u8);655 expect(@TypeOf("aoeu"[0..]) == []const u8);
656 const array = [_]i32{ 1, 2, 3, 4 };656 const array = [_]i32{ 1, 2, 3, 4 };
657 expect(@typeOf(array[0..]) == []const i32);657 expect(@TypeOf(array[0..]) == []const i32);
658 }658 }
659}659}
660660
test/stage1/behavior/pointers.zig+17-13
...@@ -93,10 +93,10 @@ test "peer type resolution with C pointers" {...@@ -93,10 +93,10 @@ test "peer type resolution with C pointers" {
93 var x2 = if (t) ptr_many else ptr_c;93 var x2 = if (t) ptr_many else ptr_c;
94 var x3 = if (t) ptr_c else ptr_one;94 var x3 = if (t) ptr_c else ptr_one;
95 var x4 = if (t) ptr_c else ptr_many;95 var x4 = if (t) ptr_c else ptr_many;
96 expect(@typeOf(x1) == [*c]u8);96 expect(@TypeOf(x1) == [*c]u8);
97 expect(@typeOf(x2) == [*c]u8);97 expect(@TypeOf(x2) == [*c]u8);
98 expect(@typeOf(x3) == [*c]u8);98 expect(@TypeOf(x3) == [*c]u8);
99 expect(@typeOf(x4) == [*c]u8);99 expect(@TypeOf(x4) == [*c]u8);
100}100}
101101
102test "implicit casting between C pointer and optional non-C pointer" {102test "implicit casting between C pointer and optional non-C pointer" {
...@@ -144,11 +144,11 @@ test "allowzero pointer and slice" {...@@ -144,11 +144,11 @@ test "allowzero pointer and slice" {
144 expect(opt_ptr != null);144 expect(opt_ptr != null);
145 expect(@ptrToInt(ptr) == 0);145 expect(@ptrToInt(ptr) == 0);
146 var slice = ptr[0..10];146 var slice = ptr[0..10];
147 expect(@typeOf(slice) == []allowzero i32);147 expect(@TypeOf(slice) == []allowzero i32);
148 expect(@ptrToInt(&slice[5]) == 20);148 expect(@ptrToInt(&slice[5]) == 20);
149149
150 expect(@typeInfo(@typeOf(ptr)).Pointer.is_allowzero);150 expect(@typeInfo(@TypeOf(ptr)).Pointer.is_allowzero);
151 expect(@typeInfo(@typeOf(slice)).Pointer.is_allowzero);151 expect(@typeInfo(@TypeOf(slice)).Pointer.is_allowzero);
152}152}
153153
154test "assign null directly to C pointer and test null equality" {154test "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" {...@@ -204,7 +204,7 @@ test "assign null directly to C pointer and test null equality" {
204test "null terminated pointer" {204test "null terminated pointer" {
205 const S = struct {205 const S = struct {
206 fn doTheTest() void {206 fn doTheTest() void {
207 var array_with_zero = [_:0]u8{'h', 'e', 'l', 'l', 'o'};207 var array_with_zero = [_:0]u8{ 'h', 'e', 'l', 'l', 'o' };
208 var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero);208 var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero);
209 var no_zero_ptr: [*]const u8 = zero_ptr;209 var no_zero_ptr: [*]const u8 = zero_ptr;
210 var zero_ptr_again = @ptrCast([*:0]const u8, no_zero_ptr);210 var zero_ptr_again = @ptrCast([*:0]const u8, no_zero_ptr);
...@@ -218,7 +218,7 @@ test "null terminated pointer" {...@@ -218,7 +218,7 @@ test "null terminated pointer" {
218test "allow any sentinel" {218test "allow any sentinel" {
219 const S = struct {219 const S = struct {
220 fn doTheTest() void {220 fn doTheTest() void {
221 var array = [_:std.math.minInt(i32)]i32{1, 2, 3, 4};221 var array = [_:std.math.minInt(i32)]i32{ 1, 2, 3, 4 };
222 var ptr: [*:std.math.minInt(i32)]i32 = &array;222 var ptr: [*:std.math.minInt(i32)]i32 = &array;
223 expect(ptr[4] == std.math.minInt(i32));223 expect(ptr[4] == std.math.minInt(i32));
224 }224 }
...@@ -229,10 +229,14 @@ test "allow any sentinel" {...@@ -229,10 +229,14 @@ test "allow any sentinel" {
229229
230test "pointer sentinel with enums" {230test "pointer sentinel with enums" {
231 const S = struct {231 const S = struct {
232 const Number = enum{one, two, sentinel};232 const Number = enum {
233 one,
234 two,
235 sentinel,
236 };
233237
234 fn doTheTest() void {238 fn doTheTest() void {
235 var ptr: [*:.sentinel]Number = &[_:.sentinel]Number{.one, .two, .two, .one};239 var ptr: [*:.sentinel]Number = &[_:.sentinel]Number{ .one, .two, .two, .one };
236 expect(ptr[4] == .sentinel); // TODO this should be comptime expect, see #3731240 expect(ptr[4] == .sentinel); // TODO this should be comptime expect, see #3731
237 }241 }
238 };242 };
...@@ -243,7 +247,7 @@ test "pointer sentinel with enums" {...@@ -243,7 +247,7 @@ test "pointer sentinel with enums" {
243test "pointer sentinel with optional element" {247test "pointer sentinel with optional element" {
244 const S = struct {248 const S = struct {
245 fn doTheTest() void {249 fn doTheTest() void {
246 var ptr: [*:null]?i32 = &[_:null]?i32{1, 2, 3, 4};250 var ptr: [*:null]?i32 = &[_:null]?i32{ 1, 2, 3, 4 };
247 expect(ptr[4] == null); // TODO this should be comptime expect, see #3731251 expect(ptr[4] == null); // TODO this should be comptime expect, see #3731
248 }252 }
249 };253 };
...@@ -255,7 +259,7 @@ test "pointer sentinel with +inf" {...@@ -255,7 +259,7 @@ test "pointer sentinel with +inf" {
255 const S = struct {259 const S = struct {
256 fn doTheTest() void {260 fn doTheTest() void {
257 const inf = std.math.inf_f32;261 const inf = std.math.inf_f32;
258 var ptr: [*:inf]f32 = &[_:inf]f32{1.1, 2.2, 3.3, 4.4};262 var ptr: [*:inf]f32 = &[_:inf]f32{ 1.1, 2.2, 3.3, 4.4 };
259 expect(ptr[4] == inf); // TODO this should be comptime expect, see #3731263 expect(ptr[4] == inf); // TODO this should be comptime expect, see #3731
260 }264 }
261 };265 };
test/stage1/behavior/ptrcast.zig+1-1
...@@ -55,7 +55,7 @@ test "comptime ptrcast keeps larger alignment" {...@@ -55,7 +55,7 @@ test "comptime ptrcast keeps larger alignment" {
55 comptime {55 comptime {
56 const a: u32 = 1234;56 const a: u32 = 1234;
57 const p = @ptrCast([*]const u8, &a);57 const p = @ptrCast([*]const u8, &a);
58 std.debug.assert(@typeOf(p) == [*]align(@alignOf(u32)) const u8);58 std.debug.assert(@TypeOf(p) == [*]align(@alignOf(u32)) const u8);
59 }59 }
60}60}
6161
test/stage1/behavior/reflection.zig+6-6
...@@ -13,12 +13,12 @@ test "reflection: array, pointer, optional, error union type child" {...@@ -13,12 +13,12 @@ test "reflection: array, pointer, optional, error union type child" {
1313
14test "reflection: function return type, var args, and param types" {14test "reflection: function return type, var args, and param types" {
15 comptime {15 comptime {
16 expect(@typeOf(dummy).ReturnType == i32);16 expect(@TypeOf(dummy).ReturnType == i32);
17 expect(!@typeOf(dummy).is_var_args);17 expect(!@TypeOf(dummy).is_var_args);
18 expect(@typeOf(dummy).arg_count == 3);18 expect(@TypeOf(dummy).arg_count == 3);
19 expect(@ArgType(@typeOf(dummy), 0) == bool);19 expect(@ArgType(@TypeOf(dummy), 0) == bool);
20 expect(@ArgType(@typeOf(dummy), 1) == i32);20 expect(@ArgType(@TypeOf(dummy), 1) == i32);
21 expect(@ArgType(@typeOf(dummy), 2) == f32);21 expect(@ArgType(@TypeOf(dummy), 2) == f32);
22 }22 }
23}23}
2424
test/stage1/behavior/sizeof_and_typeof.zig+10-10
...@@ -1,12 +1,12 @@...@@ -1,12 +1,12 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const expect = @import("std").testing.expect;2const expect = @import("std").testing.expect;
33
4test "@sizeOf and @typeOf" {4test "@sizeOf and @TypeOf" {
5 const y: @typeOf(x) = 120;5 const y: @TypeOf(x) = 120;
6 expect(@sizeOf(@typeOf(y)) == 2);6 expect(@sizeOf(@TypeOf(y)) == 2);
7}7}
8const x: u16 = 13;8const x: u16 = 13;
9const z: @typeOf(x) = 19;9const z: @TypeOf(x) = 19;
1010
11const A = struct {11const A = struct {
12 a: u8,12 a: u8,
...@@ -71,8 +71,8 @@ test "@bitOffsetOf" {...@@ -71,8 +71,8 @@ test "@bitOffsetOf" {
71test "@sizeOf on compile-time types" {71test "@sizeOf on compile-time types" {
72 expect(@sizeOf(comptime_int) == 0);72 expect(@sizeOf(comptime_int) == 0);
73 expect(@sizeOf(comptime_float) == 0);73 expect(@sizeOf(comptime_float) == 0);
74 expect(@sizeOf(@typeOf(.hi)) == 0);74 expect(@sizeOf(@TypeOf(.hi)) == 0);
75 expect(@sizeOf(@typeOf(type)) == 0);75 expect(@sizeOf(@TypeOf(type)) == 0);
76}76}
7777
78test "@sizeOf(T) == 0 doesn't force resolving struct size" {78test "@sizeOf(T) == 0 doesn't force resolving struct size" {
...@@ -90,7 +90,7 @@ test "@sizeOf(T) == 0 doesn't force resolving struct size" {...@@ -90,7 +90,7 @@ test "@sizeOf(T) == 0 doesn't force resolving struct size" {
90 expect(@sizeOf(S.Bar) == 8);90 expect(@sizeOf(S.Bar) == 8);
91}91}
9292
93test "@typeOf() has no runtime side effects" {93test "@TypeOf() has no runtime side effects" {
94 const S = struct {94 const S = struct {
95 fn foo(comptime T: type, ptr: *T) T {95 fn foo(comptime T: type, ptr: *T) T {
96 ptr.* += 1;96 ptr.* += 1;
...@@ -98,12 +98,12 @@ test "@typeOf() has no runtime side effects" {...@@ -98,12 +98,12 @@ test "@typeOf() has no runtime side effects" {
98 }98 }
99 };99 };
100 var data: i32 = 0;100 var data: i32 = 0;
101 const T = @typeOf(S.foo(i32, &data));101 const T = @TypeOf(S.foo(i32, &data));
102 comptime expect(T == i32);102 comptime expect(T == i32);
103 expect(data == 0);103 expect(data == 0);
104}104}
105105
106test "branching logic inside @typeOf" {106test "branching logic inside @TypeOf" {
107 const S = struct {107 const S = struct {
108 var data: i32 = 0;108 var data: i32 = 0;
109 fn foo() anyerror!i32 {109 fn foo() anyerror!i32 {
...@@ -111,7 +111,7 @@ test "branching logic inside @typeOf" {...@@ -111,7 +111,7 @@ test "branching logic inside @typeOf" {
111 return undefined;111 return undefined;
112 }112 }
113 };113 };
114 const T = @typeOf(S.foo() catch undefined);114 const T = @TypeOf(S.foo() catch undefined);
115 comptime expect(T == i32);115 comptime expect(T == i32);
116 expect(S.data == 0);116 expect(S.data == 0);
117}117}
test/stage1/behavior/switch.zig+2-2
...@@ -406,7 +406,7 @@ test "switch prongs with cases with identical payload types" {...@@ -406,7 +406,7 @@ test "switch prongs with cases with identical payload types" {
406 fn doTheSwitch1(u: Union) void {406 fn doTheSwitch1(u: Union) void {
407 switch (u) {407 switch (u) {
408 .A, .C => |e| {408 .A, .C => |e| {
409 expect(@typeOf(e) == usize);409 expect(@TypeOf(e) == usize);
410 expect(e == 8);410 expect(e == 8);
411 },411 },
412 .B => |e| @panic("fail"),412 .B => |e| @panic("fail"),
...@@ -416,7 +416,7 @@ test "switch prongs with cases with identical payload types" {...@@ -416,7 +416,7 @@ test "switch prongs with cases with identical payload types" {
416 switch (u) {416 switch (u) {
417 .A, .C => |e| @panic("fail"),417 .A, .C => |e| @panic("fail"),
418 .B => |e| {418 .B => |e| {
419 expect(@typeOf(e) == isize);419 expect(@TypeOf(e) == isize);
420 expect(e == -8);420 expect(e == -8);
421 },421 },
422 }422 }
test/stage1/behavior/type.zig+2-2
...@@ -125,10 +125,10 @@ test "Type.ComptimeInt" {...@@ -125,10 +125,10 @@ test "Type.ComptimeInt" {
125 testTypes(&[_]type{comptime_int});125 testTypes(&[_]type{comptime_int});
126}126}
127test "Type.Undefined" {127test "Type.Undefined" {
128 testTypes(&[_]type{@typeOf(undefined)});128 testTypes(&[_]type{@TypeOf(undefined)});
129}129}
130test "Type.Null" {130test "Type.Null" {
131 testTypes(&[_]type{@typeOf(null)});131 testTypes(&[_]type{@TypeOf(null)});
132}132}
133test "@Type create slice with null sentinel" {133test "@Type create slice with null sentinel" {
134 const Slice = @Type(builtin.TypeInfo{134 const Slice = @Type(builtin.TypeInfo{
test/stage1/behavior/type_info.zig+3-3
...@@ -201,7 +201,7 @@ fn testUnion() void {...@@ -201,7 +201,7 @@ fn testUnion() void {
201 expect(typeinfo_info.Union.fields.len == 25);201 expect(typeinfo_info.Union.fields.len == 25);
202 expect(typeinfo_info.Union.fields[4].enum_field != null);202 expect(typeinfo_info.Union.fields[4].enum_field != null);
203 expect(typeinfo_info.Union.fields[4].enum_field.?.value == 4);203 expect(typeinfo_info.Union.fields[4].enum_field.?.value == 4);
204 expect(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int));204 expect(typeinfo_info.Union.fields[4].field_type == @TypeOf(@typeInfo(u8).Int));
205 expect(typeinfo_info.Union.decls.len == 21);205 expect(typeinfo_info.Union.decls.len == 21);
206206
207 const TestNoTagUnion = union {207 const TestNoTagUnion = union {
...@@ -264,7 +264,7 @@ test "type info: function type info" {...@@ -264,7 +264,7 @@ test "type info: function type info" {
264}264}
265265
266fn testFunction() void {266fn testFunction() void {
267 const fn_info = @typeInfo(@typeOf(foo));267 const fn_info = @typeInfo(@TypeOf(foo));
268 expect(@as(TypeId, fn_info) == TypeId.Fn);268 expect(@as(TypeId, fn_info) == TypeId.Fn);
269 expect(fn_info.Fn.calling_convention == TypeInfo.CallingConvention.Unspecified);269 expect(fn_info.Fn.calling_convention == TypeInfo.CallingConvention.Unspecified);
270 expect(fn_info.Fn.is_generic);270 expect(fn_info.Fn.is_generic);
...@@ -273,7 +273,7 @@ fn testFunction() void {...@@ -273,7 +273,7 @@ fn testFunction() void {
273 expect(fn_info.Fn.return_type == null);273 expect(fn_info.Fn.return_type == null);
274274
275 const test_instance: TestStruct = undefined;275 const test_instance: TestStruct = undefined;
276 const bound_fn_info = @typeInfo(@typeOf(test_instance.foo));276 const bound_fn_info = @typeInfo(@TypeOf(test_instance.foo));
277 expect(@as(TypeId, bound_fn_info) == TypeId.BoundFn);277 expect(@as(TypeId, bound_fn_info) == TypeId.BoundFn);
278 expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct);278 expect(bound_fn_info.BoundFn.args[0].arg_type.? == *const TestStruct);
279}279}
test/stage1/behavior/undefined.zig+1-1
...@@ -64,5 +64,5 @@ test "assign undefined to struct with method" {...@@ -64,5 +64,5 @@ test "assign undefined to struct with method" {
6464
65test "type name of undefined" {65test "type name of undefined" {
66 const x = undefined;66 const x = undefined;
67 expect(mem.eql(u8, @typeName(@typeOf(x)), "(undefined)"));67 expect(mem.eql(u8, @typeName(@TypeOf(x)), "(undefined)"));
68}68}
test/stage1/behavior/vector.zig+1-1
...@@ -148,7 +148,7 @@ test "vector @splat" {...@@ -148,7 +148,7 @@ test "vector @splat" {
148 fn doTheTest() void {148 fn doTheTest() void {
149 var v: u32 = 5;149 var v: u32 = 5;
150 var x = @splat(4, v);150 var x = @splat(4, v);
151 expect(@typeOf(x) == @Vector(4, u32));151 expect(@TypeOf(x) == @Vector(4, u32));
152 var array_x: [4]u32 = x;152 var array_x: [4]u32 = x;
153 expect(array_x[0] == 5);153 expect(array_x[0] == 5);
154 expect(array_x[1] == 5);154 expect(array_x[1] == 5);
test/translate_c.zig+1-1
...@@ -1539,7 +1539,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1539,7 +1539,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1539 cases.add("macro pointer cast",1539 cases.add("macro pointer cast",
1540 \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE)1540 \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE)
1541 , &[_][]const u8{1541 , &[_][]const u8{
1542 \\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);1542 \\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);
1543 });1543 });
15441544
1545 cases.add("if on non-bool",1545 cases.add("if on non-bool",
tools/merge_anal_dumps.zig+1-1
...@@ -311,7 +311,7 @@ const Dump = struct {...@@ -311,7 +311,7 @@ const Dump = struct {
311 }311 }
312312
313 fn render(self: *Dump, stream: var) !void {313 fn render(self: *Dump, stream: var) !void {
314 var jw = json.WriteStream(@typeOf(stream).Child, 10).init(stream);314 var jw = json.WriteStream(@TypeOf(stream).Child, 10).init(stream);
315 try jw.beginObject();315 try jw.beginObject();
316316
317 try jw.objectField("typeKinds");317 try jw.objectField("typeKinds");