| author | |
| committer | |
| log | 9561e7c6b9fb2d9ebcbfd611196db698372ae7bd |
| tree | 6b4fd0751e80a9c4128756d59d3c0bfecd230498 |
| parent | cd4d638d10365e47bcb371119dcee22581355ac4 |
| parent | 30715560c829d5636734edf7eabff3ee4d170e5d |
| signature | Commit is signed but in an unrecognized format. |
closes #3875
closes #1348134 files changed, 604 insertions(+), 585 deletions(-)
doc/langref.html.in+52-52| ... | ... | @@ -307,7 +307,7 @@ pub fn main() void { |
| 307 | 307 | assert(optional_value == null); |
| 308 | 308 | |
| 309 | 309 | warn("\noptional 1\ntype: {}\nvalue: {}\n", .{ |
| 310 | @typeName(@typeOf(optional_value)), | |
| 310 | @typeName(@TypeOf(optional_value)), | |
| 311 | 311 | optional_value, |
| 312 | 312 | }); |
| 313 | 313 | |
| ... | ... | @@ -315,7 +315,7 @@ pub fn main() void { |
| 315 | 315 | assert(optional_value != null); |
| 316 | 316 | |
| 317 | 317 | warn("\noptional 2\ntype: {}\nvalue: {}\n", .{ |
| 318 | @typeName(@typeOf(optional_value)), | |
| 318 | @typeName(@TypeOf(optional_value)), | |
| 319 | 319 | optional_value, |
| 320 | 320 | }); |
| 321 | 321 | |
| ... | ... | @@ -323,14 +323,14 @@ pub fn main() void { |
| 323 | 323 | var number_or_error: anyerror!i32 = error.ArgNotFound; |
| 324 | 324 | |
| 325 | 325 | warn("\nerror union 1\ntype: {}\nvalue: {}\n", .{ |
| 326 | @typeName(@typeOf(number_or_error)), | |
| 326 | @typeName(@TypeOf(number_or_error)), | |
| 327 | 327 | number_or_error, |
| 328 | 328 | }); |
| 329 | 329 | |
| 330 | 330 | number_or_error = 1234; |
| 331 | 331 | |
| 332 | 332 | warn("\nerror union 2\ntype: {}\nvalue: {}\n", .{ |
| 333 | @typeName(@typeOf(number_or_error)), | |
| 333 | @typeName(@TypeOf(number_or_error)), | |
| 334 | 334 | number_or_error, |
| 335 | 335 | }); |
| 336 | 336 | } |
| ... | ... | @@ -572,7 +572,7 @@ const mem = @import("std").mem; |
| 572 | 572 | |
| 573 | 573 | test "string literals" { |
| 574 | 574 | const bytes = "hello"; |
| 575 | assert(@typeOf(bytes) == *const [5:0]u8); | |
| 575 | assert(@TypeOf(bytes) == *const [5:0]u8); | |
| 576 | 576 | assert(bytes.len == 5); |
| 577 | 577 | assert(bytes[1] == 'e'); |
| 578 | 578 | assert(bytes[5] == 0); |
| ... | ... | @@ -1802,7 +1802,7 @@ const assert = std.debug.assert; |
| 1802 | 1802 | test "null terminated array" { |
| 1803 | 1803 | const array = [_:0]u8 {1, 2, 3, 4}; |
| 1804 | 1804 | |
| 1805 | assert(@typeOf(array) == [4:0]u8); | |
| 1805 | assert(@TypeOf(array) == [4:0]u8); | |
| 1806 | 1806 | assert(array.len == 4); |
| 1807 | 1807 | assert(array[4] == 0); |
| 1808 | 1808 | } |
| ... | ... | @@ -1885,12 +1885,12 @@ test "address of syntax" { |
| 1885 | 1885 | assert(x_ptr.* == 1234); |
| 1886 | 1886 | |
| 1887 | 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); | |
| 1889 | 1889 | |
| 1890 | 1890 | // If you want to mutate the value, you'd need an address of a mutable variable: |
| 1891 | 1891 | var y: i32 = 5678; |
| 1892 | 1892 | const y_ptr = &y; |
| 1893 | assert(@typeOf(y_ptr) == *i32); | |
| 1893 | assert(@TypeOf(y_ptr) == *i32); | |
| 1894 | 1894 | y_ptr.* += 1; |
| 1895 | 1895 | assert(y_ptr.* == 5679); |
| 1896 | 1896 | } |
| ... | ... | @@ -1901,7 +1901,7 @@ test "pointer array access" { |
| 1901 | 1901 | // does not support pointer arithmetic. |
| 1902 | 1902 | var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; |
| 1903 | 1903 | const ptr = &array[2]; |
| 1904 | assert(@typeOf(ptr) == *u8); | |
| 1904 | assert(@TypeOf(ptr) == *u8); | |
| 1905 | 1905 | |
| 1906 | 1906 | assert(array[2] == 3); |
| 1907 | 1907 | ptr.* += 1; |
| ... | ... | @@ -1953,7 +1953,7 @@ const assert = @import("std").debug.assert; |
| 1953 | 1953 | test "@ptrToInt and @intToPtr" { |
| 1954 | 1954 | const ptr = @intToPtr(*i32, 0xdeadbeef); |
| 1955 | 1955 | const addr = @ptrToInt(ptr); |
| 1956 | assert(@typeOf(addr) == usize); | |
| 1956 | assert(@TypeOf(addr) == usize); | |
| 1957 | 1957 | assert(addr == 0xdeadbeef); |
| 1958 | 1958 | } |
| 1959 | 1959 | {#code_end#} |
| ... | ... | @@ -1968,7 +1968,7 @@ test "comptime @intToPtr" { |
| 1968 | 1968 | // ptr is never dereferenced. |
| 1969 | 1969 | const ptr = @intToPtr(*i32, 0xdeadbeef); |
| 1970 | 1970 | const addr = @ptrToInt(ptr); |
| 1971 | assert(@typeOf(addr) == usize); | |
| 1971 | assert(@TypeOf(addr) == usize); | |
| 1972 | 1972 | assert(addr == 0xdeadbeef); |
| 1973 | 1973 | } |
| 1974 | 1974 | } |
| ... | ... | @@ -1984,7 +1984,7 @@ const assert = @import("std").debug.assert; |
| 1984 | 1984 | |
| 1985 | 1985 | test "volatile" { |
| 1986 | 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 | 1989 | {#code_end#} |
| 1990 | 1990 | <p> |
| ... | ... | @@ -2041,8 +2041,8 @@ const builtin = @import("builtin"); |
| 2041 | 2041 | |
| 2042 | 2042 | test "variable alignment" { |
| 2043 | 2043 | var x: i32 = 1234; |
| 2044 | const align_of_i32 = @alignOf(@typeOf(x)); | |
| 2045 | assert(@typeOf(&x) == *i32); | |
| 2044 | const align_of_i32 = @alignOf(@TypeOf(x)); | |
| 2045 | assert(@TypeOf(&x) == *i32); | |
| 2046 | 2046 | assert(*i32 == *align(align_of_i32) i32); |
| 2047 | 2047 | if (builtin.arch == builtin.Arch.x86_64) { |
| 2048 | 2048 | assert((*i32).alignment == 4); |
| ... | ... | @@ -2063,10 +2063,10 @@ const assert = @import("std").debug.assert; |
| 2063 | 2063 | var foo: u8 align(4) = 100; |
| 2064 | 2064 | |
| 2065 | 2065 | test "global variable alignment" { |
| 2066 | assert(@typeOf(&foo).alignment == 4); | |
| 2067 | assert(@typeOf(&foo) == *align(4) u8); | |
| 2066 | assert(@TypeOf(&foo).alignment == 4); | |
| 2067 | assert(@TypeOf(&foo) == *align(4) u8); | |
| 2068 | 2068 | const slice = @as(*[1]u8, &foo)[0..]; |
| 2069 | assert(@typeOf(slice) == []align(4) u8); | |
| 2069 | assert(@TypeOf(slice) == []align(4) u8); | |
| 2070 | 2070 | } |
| 2071 | 2071 | |
| 2072 | 2072 | fn derp() align(@sizeOf(usize) * 2) i32 { return 1234; } |
| ... | ... | @@ -2075,8 +2075,8 @@ fn noop4() align(4) void {} |
| 2075 | 2075 | |
| 2076 | 2076 | test "function alignment" { |
| 2077 | 2077 | assert(derp() == 1234); |
| 2078 | assert(@typeOf(noop1) == fn() align(1) void); | |
| 2079 | assert(@typeOf(noop4) == fn() align(4) void); | |
| 2078 | assert(@TypeOf(noop1) == fn() align(1) void); | |
| 2079 | assert(@TypeOf(noop4) == fn() align(4) void); | |
| 2080 | 2080 | noop1(); |
| 2081 | 2081 | noop4(); |
| 2082 | 2082 | } |
| ... | ... | @@ -2162,8 +2162,8 @@ test "basic slices" { |
| 2162 | 2162 | |
| 2163 | 2163 | // Using the address-of operator on a slice gives a pointer to a single |
| 2164 | 2164 | // item, while using the `ptr` field gives an unknown length pointer. |
| 2165 | assert(@typeOf(slice.ptr) == [*]i32); | |
| 2166 | assert(@typeOf(&slice[0]) == *i32); | |
| 2165 | assert(@TypeOf(slice.ptr) == [*]i32); | |
| 2166 | assert(@TypeOf(&slice[0]) == *i32); | |
| 2167 | 2167 | assert(@ptrToInt(slice.ptr) == @ptrToInt(&slice[0])); |
| 2168 | 2168 | |
| 2169 | 2169 | // Slices have array bounds checking. If you try to access something out |
| ... | ... | @@ -2208,7 +2208,7 @@ test "slice pointer" { |
| 2208 | 2208 | slice[2] = 3; |
| 2209 | 2209 | assert(slice[2] == 3); |
| 2210 | 2210 | // The slice is mutable because we sliced a mutable pointer. |
| 2211 | assert(@typeOf(slice) == []u8); | |
| 2211 | assert(@TypeOf(slice) == []u8); | |
| 2212 | 2212 | |
| 2213 | 2213 | // You can also slice a slice: |
| 2214 | 2214 | const slice2 = slice[2..3]; |
| ... | ... | @@ -3566,7 +3566,7 @@ test "for basics" { |
| 3566 | 3566 | // This is zero-indexed. |
| 3567 | 3567 | var sum2: i32 = 0; |
| 3568 | 3568 | for (items) |value, i| { |
| 3569 | assert(@typeOf(i) == usize); | |
| 3569 | assert(@TypeOf(i) == usize); | |
| 3570 | 3570 | sum2 += @intCast(i32, i); |
| 3571 | 3571 | } |
| 3572 | 3572 | assert(sum2 == 10); |
| ... | ... | @@ -3909,7 +3909,7 @@ test "type of unreachable" { |
| 3909 | 3909 | // However this assertion will still fail because |
| 3910 | 3910 | // evaluating unreachable at compile-time is a compile error. |
| 3911 | 3911 | |
| 3912 | assert(@typeOf(unreachable) == noreturn); | |
| 3912 | assert(@TypeOf(unreachable) == noreturn); | |
| 3913 | 3913 | } |
| 3914 | 3914 | } |
| 3915 | 3915 | {#code_end#} |
| ... | ... | @@ -4018,7 +4018,7 @@ test "function" { |
| 4018 | 4018 | const assert = @import("std").debug.assert; |
| 4019 | 4019 | |
| 4020 | 4020 | comptime { |
| 4021 | assert(@typeOf(foo) == fn()void); | |
| 4021 | assert(@TypeOf(foo) == fn()void); | |
| 4022 | 4022 | assert(@sizeOf(fn()void) == @sizeOf(?fn()void)); |
| 4023 | 4023 | } |
| 4024 | 4024 | |
| ... | ... | @@ -4062,35 +4062,35 @@ test "pass struct to function" { |
| 4062 | 4062 | </p> |
| 4063 | 4063 | {#header_close#} |
| 4064 | 4064 | {#header_open|Function Parameter Type Inference#} |
| 4065 | <p> | |
| 4066 | Function parameters can be declared with {#syntax#}var{#endsyntax#} in place of the type. | |
| 4065 | <p> | |
| 4066 | Function parameters can be declared with {#syntax#}var{#endsyntax#} in place of the type. | |
| 4067 | 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 | 4069 | </p> |
| 4070 | 4070 | {#code_begin|test#} |
| 4071 | 4071 | const assert = @import("std").debug.assert; |
| 4072 | 4072 | |
| 4073 | fn addFortyTwo(x: var) @typeOf(x) { | |
| 4073 | fn addFortyTwo(x: var) @TypeOf(x) { | |
| 4074 | 4074 | return x + 42; |
| 4075 | 4075 | } |
| 4076 | 4076 | |
| 4077 | 4077 | test "fn type inference" { |
| 4078 | 4078 | assert(addFortyTwo(1) == 43); |
| 4079 | assert(@typeOf(addFortyTwo(1)) == comptime_int); | |
| 4079 | assert(@TypeOf(addFortyTwo(1)) == comptime_int); | |
| 4080 | 4080 | var y: i64 = 2; |
| 4081 | 4081 | assert(addFortyTwo(y) == 44); |
| 4082 | assert(@typeOf(addFortyTwo(y)) == i64); | |
| 4082 | assert(@TypeOf(addFortyTwo(y)) == i64); | |
| 4083 | 4083 | } |
| 4084 | 4084 | {#code_end#} |
| 4085 | ||
| 4085 | ||
| 4086 | 4086 | {#header_close#} |
| 4087 | 4087 | {#header_open|Function Reflection#} |
| 4088 | 4088 | {#code_begin|test#} |
| 4089 | 4089 | const assert = @import("std").debug.assert; |
| 4090 | 4090 | |
| 4091 | 4091 | test "fn reflection" { |
| 4092 | assert(@typeOf(assert).ReturnType == void); | |
| 4093 | assert(@typeOf(assert).is_var_args == false); | |
| 4092 | assert(@TypeOf(assert).ReturnType == void); | |
| 4093 | assert(@TypeOf(assert).is_var_args == false); | |
| 4094 | 4094 | } |
| 4095 | 4095 | {#code_end#} |
| 4096 | 4096 | {#header_close#} |
| ... | ... | @@ -4390,10 +4390,10 @@ test "error union" { |
| 4390 | 4390 | foo = error.SomeError; |
| 4391 | 4391 | |
| 4392 | 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); | |
| 4394 | 4394 | |
| 4395 | 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 | 4398 | {#code_end#} |
| 4399 | 4399 | {#header_open|Merging Error Sets#} |
| ... | ... | @@ -4770,7 +4770,7 @@ test "optional type" { |
| 4770 | 4770 | foo = 1234; |
| 4771 | 4771 | |
| 4772 | 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 | 4775 | {#code_end#} |
| 4776 | 4776 | {#header_close#} |
| ... | ... | @@ -5154,7 +5154,7 @@ test "peer resolve int widening" { |
| 5154 | 5154 | var b: i16 = 34; |
| 5155 | 5155 | var c = a + b; |
| 5156 | 5156 | assert(c == 46); |
| 5157 | assert(@typeOf(c) == i16); | |
| 5157 | assert(@TypeOf(c) == i16); | |
| 5158 | 5158 | } |
| 5159 | 5159 | |
| 5160 | 5160 | test "peer resolve arrays of different size to const slice" { |
| ... | ... | @@ -5949,7 +5949,7 @@ pub fn printf(self: *OutStream, arg0: i32, arg1: []const u8) !void { |
| 5949 | 5949 | </p> |
| 5950 | 5950 | {#code_begin|syntax#} |
| 5951 | 5951 | pub fn printValue(self: *OutStream, value: var) !void { |
| 5952 | const T = @typeOf(value); | |
| 5952 | const T = @TypeOf(value); | |
| 5953 | 5953 | if (@isInteger(T)) { |
| 5954 | 5954 | return self.printInt(T, value); |
| 5955 | 5955 | } else if (@isFloat(T)) { |
| ... | ... | @@ -6265,7 +6265,7 @@ test "async function suspend with block" { |
| 6265 | 6265 | |
| 6266 | 6266 | fn testSuspendBlock() void { |
| 6267 | 6267 | suspend { |
| 6268 | comptime assert(@typeOf(@frame()) == *@Frame(testSuspendBlock)); | |
| 6268 | comptime assert(@TypeOf(@frame()) == *@Frame(testSuspendBlock)); | |
| 6269 | 6269 | the_frame = @frame(); |
| 6270 | 6270 | } |
| 6271 | 6271 | result = true; |
| ... | ... | @@ -6332,7 +6332,7 @@ test "async and await" { |
| 6332 | 6332 | |
| 6333 | 6333 | fn amain() void { |
| 6334 | 6334 | var frame = async func(); |
| 6335 | comptime assert(@typeOf(frame) == @Frame(func)); | |
| 6335 | comptime assert(@TypeOf(frame) == @Frame(func)); | |
| 6336 | 6336 | |
| 6337 | 6337 | const ptr: anyframe->void = &frame; |
| 6338 | 6338 | const any_ptr: anyframe = ptr; |
| ... | ... | @@ -6740,7 +6740,7 @@ async fn func(y: *i32) void { |
| 6740 | 6740 | Converts a value of one type to another type. |
| 6741 | 6741 | </p> |
| 6742 | 6742 | <p> |
| 6743 | Asserts that {#syntax#}@sizeOf(@typeOf(value)) == @sizeOf(DestType){#endsyntax#}. | |
| 6743 | Asserts that {#syntax#}@sizeOf(@TypeOf(value)) == @sizeOf(DestType){#endsyntax#}. | |
| 6744 | 6744 | </p> |
| 6745 | 6745 | <p> |
| 6746 | 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 | 7045 | <p> |
| 7046 | 7046 | {#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("builtin").AtomicOrder{#endsyntax#}. |
| 7047 | 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 | 7049 | {#see_also|Compile Variables|cmpxchgWeak#} |
| 7050 | 7050 | {#header_close#} |
| 7051 | 7051 | {#header_open|@cmpxchgWeak#} |
| ... | ... | @@ -7073,7 +7073,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val |
| 7073 | 7073 | <p> |
| 7074 | 7074 | {#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("builtin").AtomicOrder{#endsyntax#}. |
| 7075 | 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 | 7077 | {#see_also|Compile Variables|cmpxchgStrong#} |
| 7078 | 7078 | {#header_close#} |
| 7079 | 7079 | |
| ... | ... | @@ -8020,7 +8020,7 @@ test "@setRuntimeSafety" { |
| 8020 | 8020 | {#header_close#} |
| 8021 | 8021 | |
| 8022 | 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 | 8024 | <p> |
| 8025 | 8025 | Produces a vector of length {#syntax#}len{#endsyntax#} where each element is the value |
| 8026 | 8026 | {#syntax#}scalar{#endsyntax#}: |
| ... | ... | @@ -8032,7 +8032,7 @@ const assert = std.debug.assert; |
| 8032 | 8032 | test "vector @splat" { |
| 8033 | 8033 | const scalar: u32 = 5; |
| 8034 | 8034 | const result = @splat(4, scalar); |
| 8035 | comptime assert(@typeOf(result) == @Vector(4, u32)); | |
| 8035 | comptime assert(@TypeOf(result) == @Vector(4, u32)); | |
| 8036 | 8036 | assert(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 })); |
| 8037 | 8037 | } |
| 8038 | 8038 | {#code_end#} |
| ... | ... | @@ -8250,8 +8250,8 @@ test "integer truncation" { |
| 8250 | 8250 | <li>{#link|Pointers#}</li> |
| 8251 | 8251 | <li>{#syntax#}comptime_int{#endsyntax#}</li> |
| 8252 | 8252 | <li>{#syntax#}comptime_float{#endsyntax#}</li> |
| 8253 | <li>{#syntax#}@typeOf(undefined){#endsyntax#}</li> | |
| 8254 | <li>{#syntax#}@typeOf(null){#endsyntax#}</li> | |
| 8253 | <li>{#syntax#}@TypeOf(undefined){#endsyntax#}</li> | |
| 8254 | <li>{#syntax#}@TypeOf(null){#endsyntax#}</li> | |
| 8255 | 8255 | </ul> |
| 8256 | 8256 | <p> |
| 8257 | 8257 | For these types it is a |
| ... | ... | @@ -8516,20 +8516,20 @@ pub const TypeInfo = union(TypeId) { |
| 8516 | 8516 | |
| 8517 | 8517 | {#header_close#} |
| 8518 | 8518 | |
| 8519 | {#header_open|@typeOf#} | |
| 8520 | <pre>{#syntax#}@typeOf(expression) type{#endsyntax#}</pre> | |
| 8519 | {#header_open|@TypeOf#} | |
| 8520 | <pre>{#syntax#}@TypeOf(expression) type{#endsyntax#}</pre> | |
| 8521 | 8521 | <p> |
| 8522 | 8522 | This function returns a compile-time constant, which is the type of the |
| 8523 | 8523 | expression passed as an argument. The expression is evaluated. |
| 8524 | 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 | 8526 | {#code_begin|test#} |
| 8527 | 8527 | const std = @import("std"); |
| 8528 | 8528 | const assert = std.debug.assert; |
| 8529 | 8529 | |
| 8530 | 8530 | test "no runtime side effects" { |
| 8531 | 8531 | var data: i32 = 0; |
| 8532 | const T = @typeOf(foo(i32, &data)); | |
| 8532 | const T = @TypeOf(foo(i32, &data)); | |
| 8533 | 8533 | comptime assert(T == i32); |
| 8534 | 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 | 40 | .allocator = allocator, |
| 41 | 41 | }; |
| 42 | 42 | } |
| 43 | ||
| 43 | ||
| 44 | 44 | /// Initialize with capacity to hold at least num elements. |
| 45 | 45 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| 46 | 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 | 106 | pub fn dump(self: *Self) void { |
| 107 | 107 | var stderr_file = std.io.getStdErr() catch return; |
| 108 | 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; | |
| 110 | 110 | |
| 111 | 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 | 9 | pub fn Stack(comptime T: type) type { |
| 10 | 10 | return struct { |
| 11 | 11 | root: ?*Node, |
| 12 | lock: @typeOf(lock_init), | |
| 12 | lock: @TypeOf(lock_init), | |
| 13 | 13 | |
| 14 | 14 | const lock_init = if (builtin.single_threaded) {} else @as(u8, 0); |
| 15 | 15 |
lib/std/debug.zig+4-4| ... | ... | @@ -1290,7 +1290,7 @@ pub const DwarfInfo = struct { |
| 1290 | 1290 | try di.dwarf_seekable_stream.seekTo(this_unit_offset); |
| 1291 | 1291 | |
| 1292 | 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 | 1294 | if (unit_length == 0) return; |
| 1295 | 1295 | const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4)); |
| 1296 | 1296 | |
| ... | ... | @@ -1392,7 +1392,7 @@ pub const DwarfInfo = struct { |
| 1392 | 1392 | try di.dwarf_seekable_stream.seekTo(this_unit_offset); |
| 1393 | 1393 | |
| 1394 | 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 | 1396 | if (unit_length == 0) return; |
| 1397 | 1397 | const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4)); |
| 1398 | 1398 | |
| ... | ... | @@ -1551,7 +1551,7 @@ pub const DwarfInfo = struct { |
| 1551 | 1551 | try di.dwarf_seekable_stream.seekTo(di.debug_line.offset + line_info_offset); |
| 1552 | 1552 | |
| 1553 | 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 | 1555 | if (unit_length == 0) { |
| 1556 | 1556 | return error.MissingDebugInfo; |
| 1557 | 1557 | } |
| ... | ... | @@ -2080,7 +2080,7 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64 |
| 2080 | 2080 | DW.FORM_strp => FormValue{ .StrPtr = try parseFormValueDwarfOffsetSize(in_stream, is_64) }, |
| 2081 | 2081 | DW.FORM_indirect => { |
| 2082 | 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 | 2084 | var frame = try allocator.create(F); |
| 2085 | 2085 | defer allocator.destroy(frame); |
| 2086 | 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 | 61 | /// `func` must be async and have return type `ReturnType`. |
| 62 | 62 | /// Thread-safe. |
| 63 | 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 | 65 | errdefer self.allocator.destroy(frame); |
| 66 | 66 | const node = try self.allocator.create(AllocStack.Node); |
| 67 | 67 | errdefer self.allocator.destroy(node); |
lib/std/event/loop.zig+1-1| ... | ... | @@ -42,7 +42,7 @@ pub const Loop = struct { |
| 42 | 42 | }, |
| 43 | 43 | else => {}, |
| 44 | 44 | }; |
| 45 | pub const Overlapped = @typeOf(overlapped_init); | |
| 45 | pub const Overlapped = @TypeOf(overlapped_init); | |
| 46 | 46 | |
| 47 | 47 | pub const Id = enum { |
| 48 | 48 | Basic, |
lib/std/fmt.zig+34-34| ... | ... | @@ -80,7 +80,7 @@ fn peekIsAlign(comptime fmt: []const u8) bool { |
| 80 | 80 | /// |
| 81 | 81 | /// 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!void | |
| 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!void | |
| 84 | 84 | /// ``` |
| 85 | 85 | /// with `?` being the type formatted, this function will be called instead of the default implementation. |
| 86 | 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 | 89 | pub fn format( |
| 90 | 90 | context: var, |
| 91 | 91 | comptime Errors: type, |
| 92 | output: fn (@typeOf(context), []const u8) Errors!void, | |
| 92 | output: fn (@TypeOf(context), []const u8) Errors!void, | |
| 93 | 93 | comptime fmt: []const u8, |
| 94 | 94 | args: var, |
| 95 | 95 | ) Errors!void { |
| ... | ... | @@ -320,17 +320,17 @@ pub fn formatType( |
| 320 | 320 | options: FormatOptions, |
| 321 | 321 | context: var, |
| 322 | 322 | comptime Errors: type, |
| 323 | output: fn (@typeOf(context), []const u8) Errors!void, | |
| 323 | output: fn (@TypeOf(context), []const u8) Errors!void, | |
| 324 | 324 | max_depth: usize, |
| 325 | 325 | ) Errors!void { |
| 326 | 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 | 328 | try output(context, "@"); |
| 329 | 329 | try formatInt(@ptrToInt(value), 16, false, FormatOptions{}, context, Errors, output); |
| 330 | 330 | return; |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | const T = @typeOf(value); | |
| 333 | const T = @TypeOf(value); | |
| 334 | 334 | switch (@typeInfo(T)) { |
| 335 | 335 | .ComptimeInt, .Int, .Float => { |
| 336 | 336 | return formatValue(value, fmt, options, context, Errors, output); |
| ... | ... | @@ -478,7 +478,7 @@ fn formatValue( |
| 478 | 478 | options: FormatOptions, |
| 479 | 479 | context: var, |
| 480 | 480 | comptime Errors: type, |
| 481 | output: fn (@typeOf(context), []const u8) Errors!void, | |
| 481 | output: fn (@TypeOf(context), []const u8) Errors!void, | |
| 482 | 482 | ) Errors!void { |
| 483 | 483 | if (comptime std.mem.eql(u8, fmt, "B")) { |
| 484 | 484 | return formatBytes(value, options, 1000, context, Errors, output); |
| ... | ... | @@ -486,7 +486,7 @@ fn formatValue( |
| 486 | 486 | return formatBytes(value, options, 1024, context, Errors, output); |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | const T = @typeOf(value); | |
| 489 | const T = @TypeOf(value); | |
| 490 | 490 | switch (@typeId(T)) { |
| 491 | 491 | .Float => return formatFloatValue(value, fmt, options, context, Errors, output), |
| 492 | 492 | .Int, .ComptimeInt => return formatIntValue(value, fmt, options, context, Errors, output), |
| ... | ... | @@ -500,12 +500,12 @@ pub fn formatIntValue( |
| 500 | 500 | options: FormatOptions, |
| 501 | 501 | context: var, |
| 502 | 502 | comptime Errors: type, |
| 503 | output: fn (@typeOf(context), []const u8) Errors!void, | |
| 503 | output: fn (@TypeOf(context), []const u8) Errors!void, | |
| 504 | 504 | ) Errors!void { |
| 505 | 505 | comptime var radix = 10; |
| 506 | 506 | comptime var uppercase = false; |
| 507 | 507 | |
| 508 | const int_value = if (@typeOf(value) == comptime_int) blk: { | |
| 508 | const int_value = if (@TypeOf(value) == comptime_int) blk: { | |
| 509 | 509 | const Int = math.IntFittingRange(value, value); |
| 510 | 510 | break :blk @as(Int, value); |
| 511 | 511 | } else |
| ... | ... | @@ -515,7 +515,7 @@ pub fn formatIntValue( |
| 515 | 515 | radix = 10; |
| 516 | 516 | uppercase = false; |
| 517 | 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 | 519 | return formatAsciiChar(@as(u8, int_value), options, context, Errors, output); |
| 520 | 520 | } else { |
| 521 | 521 | @compileError("Cannot print integer that is larger than 8 bits as a ascii"); |
| ... | ... | @@ -542,7 +542,7 @@ fn formatFloatValue( |
| 542 | 542 | options: FormatOptions, |
| 543 | 543 | context: var, |
| 544 | 544 | comptime Errors: type, |
| 545 | output: fn (@typeOf(context), []const u8) Errors!void, | |
| 545 | output: fn (@TypeOf(context), []const u8) Errors!void, | |
| 546 | 546 | ) Errors!void { |
| 547 | 547 | if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "e")) { |
| 548 | 548 | return formatFloatScientific(value, options, context, Errors, output); |
| ... | ... | @@ -559,7 +559,7 @@ pub fn formatText( |
| 559 | 559 | options: FormatOptions, |
| 560 | 560 | context: var, |
| 561 | 561 | comptime Errors: type, |
| 562 | output: fn (@typeOf(context), []const u8) Errors!void, | |
| 562 | output: fn (@TypeOf(context), []const u8) Errors!void, | |
| 563 | 563 | ) Errors!void { |
| 564 | 564 | if (fmt.len == 0) { |
| 565 | 565 | return output(context, bytes); |
| ... | ... | @@ -580,7 +580,7 @@ pub fn formatAsciiChar( |
| 580 | 580 | options: FormatOptions, |
| 581 | 581 | context: var, |
| 582 | 582 | comptime Errors: type, |
| 583 | output: fn (@typeOf(context), []const u8) Errors!void, | |
| 583 | output: fn (@TypeOf(context), []const u8) Errors!void, | |
| 584 | 584 | ) Errors!void { |
| 585 | 585 | return output(context, @as(*const [1]u8, &c)[0..]); |
| 586 | 586 | } |
| ... | ... | @@ -590,7 +590,7 @@ pub fn formatBuf( |
| 590 | 590 | options: FormatOptions, |
| 591 | 591 | context: var, |
| 592 | 592 | comptime Errors: type, |
| 593 | output: fn (@typeOf(context), []const u8) Errors!void, | |
| 593 | output: fn (@TypeOf(context), []const u8) Errors!void, | |
| 594 | 594 | ) Errors!void { |
| 595 | 595 | try output(context, buf); |
| 596 | 596 | |
| ... | ... | @@ -610,7 +610,7 @@ pub fn formatFloatScientific( |
| 610 | 610 | options: FormatOptions, |
| 611 | 611 | context: var, |
| 612 | 612 | comptime Errors: type, |
| 613 | output: fn (@typeOf(context), []const u8) Errors!void, | |
| 613 | output: fn (@TypeOf(context), []const u8) Errors!void, | |
| 614 | 614 | ) Errors!void { |
| 615 | 615 | var x = @floatCast(f64, value); |
| 616 | 616 | |
| ... | ... | @@ -672,7 +672,7 @@ pub fn formatFloatScientific( |
| 672 | 672 | try output(context, float_decimal.digits[0..1]); |
| 673 | 673 | try output(context, "."); |
| 674 | 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; | |
| 676 | 676 | |
| 677 | 677 | try output(context, float_decimal.digits[1..num_digits]); |
| 678 | 678 | } else { |
| ... | ... | @@ -705,7 +705,7 @@ pub fn formatFloatDecimal( |
| 705 | 705 | options: FormatOptions, |
| 706 | 706 | context: var, |
| 707 | 707 | comptime Errors: type, |
| 708 | output: fn (@typeOf(context), []const u8) Errors!void, | |
| 708 | output: fn (@TypeOf(context), []const u8) Errors!void, | |
| 709 | 709 | ) Errors!void { |
| 710 | 710 | var x = @as(f64, value); |
| 711 | 711 | |
| ... | ... | @@ -851,7 +851,7 @@ pub fn formatBytes( |
| 851 | 851 | comptime radix: usize, |
| 852 | 852 | context: var, |
| 853 | 853 | comptime Errors: type, |
| 854 | output: fn (@typeOf(context), []const u8) Errors!void, | |
| 854 | output: fn (@TypeOf(context), []const u8) Errors!void, | |
| 855 | 855 | ) Errors!void { |
| 856 | 856 | if (value == 0) { |
| 857 | 857 | return output(context, "0B"); |
| ... | ... | @@ -892,15 +892,15 @@ pub fn formatInt( |
| 892 | 892 | options: FormatOptions, |
| 893 | 893 | context: var, |
| 894 | 894 | comptime Errors: type, |
| 895 | output: fn (@typeOf(context), []const u8) Errors!void, | |
| 895 | output: fn (@TypeOf(context), []const u8) Errors!void, | |
| 896 | 896 | ) Errors!void { |
| 897 | const int_value = if (@typeOf(value) == comptime_int) blk: { | |
| 897 | const int_value = if (@TypeOf(value) == comptime_int) blk: { | |
| 898 | 898 | const Int = math.IntFittingRange(value, value); |
| 899 | 899 | break :blk @as(Int, value); |
| 900 | 900 | } else |
| 901 | 901 | value; |
| 902 | 902 | |
| 903 | if (@typeOf(int_value).is_signed) { | |
| 903 | if (@TypeOf(int_value).is_signed) { | |
| 904 | 904 | return formatIntSigned(int_value, base, uppercase, options, context, Errors, output); |
| 905 | 905 | } else { |
| 906 | 906 | return formatIntUnsigned(int_value, base, uppercase, options, context, Errors, output); |
| ... | ... | @@ -914,7 +914,7 @@ fn formatIntSigned( |
| 914 | 914 | options: FormatOptions, |
| 915 | 915 | context: var, |
| 916 | 916 | comptime Errors: type, |
| 917 | output: fn (@typeOf(context), []const u8) Errors!void, | |
| 917 | output: fn (@TypeOf(context), []const u8) Errors!void, | |
| 918 | 918 | ) Errors!void { |
| 919 | 919 | const new_options = FormatOptions{ |
| 920 | 920 | .width = if (options.width) |w| (if (w == 0) 0 else w - 1) else null, |
| ... | ... | @@ -922,7 +922,7 @@ fn formatIntSigned( |
| 922 | 922 | .fill = options.fill, |
| 923 | 923 | }; |
| 924 | 924 | |
| 925 | const uint = @IntType(false, @typeOf(value).bit_count); | |
| 925 | const uint = @IntType(false, @TypeOf(value).bit_count); | |
| 926 | 926 | if (value < 0) { |
| 927 | 927 | const minus_sign: u8 = '-'; |
| 928 | 928 | try output(context, @as(*const [1]u8, &minus_sign)[0..]); |
| ... | ... | @@ -945,12 +945,12 @@ fn formatIntUnsigned( |
| 945 | 945 | options: FormatOptions, |
| 946 | 946 | context: var, |
| 947 | 947 | comptime Errors: type, |
| 948 | output: fn (@typeOf(context), []const u8) Errors!void, | |
| 948 | output: fn (@TypeOf(context), []const u8) Errors!void, | |
| 949 | 949 | ) Errors!void { |
| 950 | 950 | assert(base >= 2); |
| 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); | |
| 953 | const MinInt = @IntType(@typeOf(value).is_signed, min_int_bits); | |
| 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); | |
| 953 | const MinInt = @IntType(@TypeOf(value).is_signed, min_int_bits); | |
| 954 | 954 | var a: MinInt = value; |
| 955 | 955 | var index: usize = buf.len; |
| 956 | 956 | |
| ... | ... | @@ -1420,7 +1420,7 @@ test "custom" { |
| 1420 | 1420 | options: FormatOptions, |
| 1421 | 1421 | context: var, |
| 1422 | 1422 | comptime Errors: type, |
| 1423 | output: fn (@typeOf(context), []const u8) Errors!void, | |
| 1423 | output: fn (@TypeOf(context), []const u8) Errors!void, | |
| 1424 | 1424 | ) Errors!void { |
| 1425 | 1425 | if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "p")) { |
| 1426 | 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 | 1610 | const value: comptime_int = 123456789123456789; |
| 1611 | 1611 | |
| 1612 | 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 | 1614 | std.testing.expect(mem.eql(u8, buf.toSlice(), "123456789123456789")); |
| 1615 | 1615 | } |
| 1616 | 1616 | |
| ... | ... | @@ -1626,7 +1626,7 @@ test "formatType max_depth" { |
| 1626 | 1626 | options: FormatOptions, |
| 1627 | 1627 | context: var, |
| 1628 | 1628 | comptime Errors: type, |
| 1629 | output: fn (@typeOf(context), []const u8) Errors!void, | |
| 1629 | output: fn (@TypeOf(context), []const u8) Errors!void, | |
| 1630 | 1630 | ) Errors!void { |
| 1631 | 1631 | if (fmt.len == 0) { |
| 1632 | 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 | 1664 | inst.tu.ptr = &inst.tu; |
| 1665 | 1665 | |
| 1666 | 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 | 1668 | std.testing.expect(mem.eql(u8, buf0.toSlice(), "S{ ... }")); |
| 1669 | 1669 | |
| 1670 | 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 | 1672 | std.testing.expect(mem.eql(u8, buf1.toSlice(), "S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }")); |
| 1673 | 1673 | |
| 1674 | 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 | 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) }")); |
| 1677 | 1677 | |
| 1678 | 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 | 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 | } |
| 1682 | 1682 |
lib/std/hash/auto_hash.zig+3-3| ... | ... | @@ -22,7 +22,7 @@ pub const HashStrategy = enum { |
| 22 | 22 | |
| 23 | 23 | /// Helper function to hash a pointer and mutate the strategy if needed. |
| 24 | 24 | pub fn hashPointer(hasher: var, key: var, comptime strat: HashStrategy) void { |
| 25 | const info = @typeInfo(@typeOf(key)); | |
| 25 | const info = @typeInfo(@TypeOf(key)); | |
| 26 | 26 | |
| 27 | 27 | switch (info.Pointer.size) { |
| 28 | 28 | builtin.TypeInfo.Pointer.Size.One => switch (strat) { |
| ... | ... | @@ -74,7 +74,7 @@ pub fn hashArray(hasher: var, key: var, comptime strat: HashStrategy) void { |
| 74 | 74 | /// Provides generic hashing for any eligible type. |
| 75 | 75 | /// Strategy is provided to determine if pointers should be followed or not. |
| 76 | 76 | pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void { |
| 77 | const Key = @typeOf(key); | |
| 77 | const Key = @TypeOf(key); | |
| 78 | 78 | switch (@typeInfo(Key)) { |
| 79 | 79 | .NoReturn, |
| 80 | 80 | .Opaque, |
| ... | ... | @@ -164,7 +164,7 @@ pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void { |
| 164 | 164 | /// Only hashes `key` itself, pointers are not followed. |
| 165 | 165 | /// Slices are rejected to avoid ambiguity on the user's intention. |
| 166 | 166 | pub fn autoHash(hasher: var, key: var) void { |
| 167 | const Key = @typeOf(key); | |
| 167 | const Key = @TypeOf(key); | |
| 168 | 168 | if (comptime meta.trait.isSlice(Key)) { |
| 169 | 169 | comptime assert(@hasDecl(std, "StringHashMap")); // detect when the following message needs updated |
| 170 | 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 | 360 | var hashes: [hashbytes * 256]u8 = undefined; |
| 361 | 361 | var final: [hashbytes]u8 = undefined; |
| 362 | 362 | |
| 363 | @memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@typeOf(key))); | |
| 364 | @memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@typeOf(hashes))); | |
| 365 | @memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@typeOf(final))); | |
| 363 | @memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@TypeOf(key))); | |
| 364 | @memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@TypeOf(hashes))); | |
| 365 | @memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@TypeOf(final))); | |
| 366 | 366 | |
| 367 | 367 | var i: u32 = 0; |
| 368 | 368 | while (i < 256) : (i += 1) { |
| ... | ... | @@ -370,7 +370,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 { |
| 370 | 370 | |
| 371 | 371 | var h = hash_fn(key[0..i], 256 - i); |
| 372 | 372 | if (builtin.endian == builtin.Endian.Big) |
| 373 | h = @byteSwap(@typeOf(h), h); | |
| 373 | h = @byteSwap(@TypeOf(h), h); | |
| 374 | 374 | @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes); |
| 375 | 375 | } |
| 376 | 376 |
lib/std/hash/murmur.zig+4-4| ... | ... | @@ -285,9 +285,9 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 { |
| 285 | 285 | var hashes: [hashbytes * 256]u8 = undefined; |
| 286 | 286 | var final: [hashbytes]u8 = undefined; |
| 287 | 287 | |
| 288 | @memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@typeOf(key))); | |
| 289 | @memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@typeOf(hashes))); | |
| 290 | @memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@typeOf(final))); | |
| 288 | @memset(@ptrCast([*]u8, &key[0]), 0, @sizeOf(@TypeOf(key))); | |
| 289 | @memset(@ptrCast([*]u8, &hashes[0]), 0, @sizeOf(@TypeOf(hashes))); | |
| 290 | @memset(@ptrCast([*]u8, &final[0]), 0, @sizeOf(@TypeOf(final))); | |
| 291 | 291 | |
| 292 | 292 | var i: u32 = 0; |
| 293 | 293 | while (i < 256) : (i += 1) { |
| ... | ... | @@ -295,7 +295,7 @@ fn SMHasherTest(comptime hash_fn: var, comptime hashbits: u32) u32 { |
| 295 | 295 | |
| 296 | 296 | var h = hash_fn(key[0..i], 256 - i); |
| 297 | 297 | if (builtin.endian == builtin.Endian.Big) |
| 298 | h = @byteSwap(@typeOf(h), h); | |
| 298 | h = @byteSwap(@TypeOf(h), h); | |
| 299 | 299 | @memcpy(@ptrCast([*]u8, &hashes[i * hashbytes]), @ptrCast([*]u8, &h), hashbytes); |
| 300 | 300 | } |
| 301 | 301 |
lib/std/http/headers.zig+1-1| ... | ... | @@ -367,7 +367,7 @@ pub const Headers = struct { |
| 367 | 367 | options: std.fmt.FormatOptions, |
| 368 | 368 | context: var, |
| 369 | 369 | comptime Errors: type, |
| 370 | output: fn (@typeOf(context), []const u8) Errors!void, | |
| 370 | output: fn (@TypeOf(context), []const u8) Errors!void, | |
| 371 | 371 | ) Errors!void { |
| 372 | 372 | var it = self.iterator(); |
| 373 | 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 | 663 | pub fn writeBits(self: *Self, value: var, bits: usize) Error!void { |
| 664 | 664 | if (bits == 0) return; |
| 665 | 665 | |
| 666 | const U = @typeOf(value); | |
| 666 | const U = @TypeOf(value); | |
| 667 | 667 | comptime assert(trait.isUnsignedInt(U)); |
| 668 | 668 | |
| 669 | 669 | //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 | 962 | |
| 963 | 963 | /// Deserializes data into the type pointed to by `ptr` |
| 964 | 964 | pub fn deserializeInto(self: *Self, ptr: var) !void { |
| 965 | const T = @typeOf(ptr); | |
| 965 | const T = @TypeOf(ptr); | |
| 966 | 966 | comptime assert(trait.is(builtin.TypeId.Pointer)(T)); |
| 967 | 967 | |
| 968 | 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 | 1091 | } |
| 1092 | 1092 | |
| 1093 | 1093 | fn serializeInt(self: *Self, value: var) Error!void { |
| 1094 | const T = @typeOf(value); | |
| 1094 | const T = @TypeOf(value); | |
| 1095 | 1095 | comptime assert(trait.is(builtin.TypeId.Int)(T) or trait.is(builtin.TypeId.Float)(T)); |
| 1096 | 1096 | |
| 1097 | 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 | 1123 | |
| 1124 | 1124 | /// Serializes the passed value into the stream |
| 1125 | 1125 | pub fn serialize(self: *Self, value: var) Error!void { |
| 1126 | const T = comptime @typeOf(value); | |
| 1126 | const T = comptime @TypeOf(value); | |
| 1127 | 1127 | |
| 1128 | 1128 | if (comptime trait.isIndexable(T)) { |
| 1129 | 1129 | for (value) |v| |
lib/std/json.zig+3-3| ... | ... | @@ -1038,7 +1038,7 @@ pub const Value = union(enum) { |
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | 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 | 1042 | w.newline = ""; |
| 1043 | 1043 | w.one_indent = ""; |
| 1044 | 1044 | w.space = ""; |
| ... | ... | @@ -1048,7 +1048,7 @@ pub const Value = union(enum) { |
| 1048 | 1048 | pub fn dumpStreamIndent(self: @This(), comptime indent: usize, stream: var, comptime max_depth: usize) !void { |
| 1049 | 1049 | var one_indent = " " ** indent; |
| 1050 | 1050 | |
| 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 | 1052 | w.one_indent = one_indent; |
| 1053 | 1053 | try w.emitJson(self); |
| 1054 | 1054 | } |
| ... | ... | @@ -1338,7 +1338,7 @@ test "write json then parse it" { |
| 1338 | 1338 | |
| 1339 | 1339 | var slice_out_stream = std.io.SliceOutStream.init(&out_buffer); |
| 1340 | 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); | |
| 1342 | 1342 | |
| 1343 | 1343 | try jw.beginObject(); |
| 1344 | 1344 |
lib/std/json/write_stream.zig+2-2| ... | ... | @@ -155,7 +155,7 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type { |
| 155 | 155 | value: var, |
| 156 | 156 | ) !void { |
| 157 | 157 | assert(self.state[self.state_index] == State.Value); |
| 158 | switch (@typeInfo(@typeOf(value))) { | |
| 158 | switch (@typeInfo(@TypeOf(value))) { | |
| 159 | 159 | .Int => |info| { |
| 160 | 160 | if (info.bits < 53) { |
| 161 | 161 | try self.stream.print("{}", .{value}); |
| ... | ... | @@ -257,7 +257,7 @@ test "json write stream" { |
| 257 | 257 | var mem_buf: [1024 * 10]u8 = undefined; |
| 258 | 258 | const allocator = &std.heap.FixedBufferAllocator.init(&mem_buf).allocator; |
| 259 | 259 | |
| 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 | 261 | try w.emitJson(try getJson(allocator)); |
| 262 | 262 | |
| 263 | 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 | 95 | |
| 96 | 96 | // TODO: Hide the following in an internal module. |
| 97 | 97 | pub fn forceEval(value: var) void { |
| 98 | const T = @typeOf(value); | |
| 98 | const T = @TypeOf(value); | |
| 99 | 99 | switch (T) { |
| 100 | 100 | f16 => { |
| 101 | 101 | var x: f16 = undefined; |
| ... | ... | @@ -239,13 +239,13 @@ pub fn Min(comptime A: type, comptime B: type) type { |
| 239 | 239 | }, |
| 240 | 240 | else => {}, |
| 241 | 241 | } |
| 242 | return @typeOf(@as(A, 0) + @as(B, 0)); | |
| 242 | return @TypeOf(@as(A, 0) + @as(B, 0)); | |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /// Returns the smaller number. When one of the parameter's type's full range fits in the other, |
| 246 | 246 | /// the return type is the smaller type. |
| 247 | pub fn min(x: var, y: var) Min(@typeOf(x), @typeOf(y)) { | |
| 248 | const Result = Min(@typeOf(x), @typeOf(y)); | |
| 247 | pub fn min(x: var, y: var) Min(@TypeOf(x), @TypeOf(y)) { | |
| 248 | const Result = Min(@TypeOf(x), @TypeOf(y)); | |
| 249 | 249 | if (x < y) { |
| 250 | 250 | // TODO Zig should allow this as an implicit cast because x is immutable and in this |
| 251 | 251 | // scope it is known to fit in the return type. |
| ... | ... | @@ -269,33 +269,33 @@ test "math.min" { |
| 269 | 269 | var a: u16 = 999; |
| 270 | 270 | var b: u32 = 10; |
| 271 | 271 | var result = min(a, b); |
| 272 | testing.expect(@typeOf(result) == u16); | |
| 272 | testing.expect(@TypeOf(result) == u16); | |
| 273 | 273 | testing.expect(result == 10); |
| 274 | 274 | } |
| 275 | 275 | { |
| 276 | 276 | var a: f64 = 10.34; |
| 277 | 277 | var b: f32 = 999.12; |
| 278 | 278 | var result = min(a, b); |
| 279 | testing.expect(@typeOf(result) == f64); | |
| 279 | testing.expect(@TypeOf(result) == f64); | |
| 280 | 280 | testing.expect(result == 10.34); |
| 281 | 281 | } |
| 282 | 282 | { |
| 283 | 283 | var a: i8 = -127; |
| 284 | 284 | var b: i16 = -200; |
| 285 | 285 | var result = min(a, b); |
| 286 | testing.expect(@typeOf(result) == i16); | |
| 286 | testing.expect(@TypeOf(result) == i16); | |
| 287 | 287 | testing.expect(result == -200); |
| 288 | 288 | } |
| 289 | 289 | { |
| 290 | 290 | const a = 10.34; |
| 291 | 291 | var b: f32 = 999.12; |
| 292 | 292 | var result = min(a, b); |
| 293 | testing.expect(@typeOf(result) == f32); | |
| 293 | testing.expect(@TypeOf(result) == f32); | |
| 294 | 294 | testing.expect(result == 10.34); |
| 295 | 295 | } |
| 296 | 296 | } |
| 297 | 297 | |
| 298 | pub fn max(x: var, y: var) @typeOf(x + y) { | |
| 298 | pub fn max(x: var, y: var) @TypeOf(x + y) { | |
| 299 | 299 | return if (x > y) x else y; |
| 300 | 300 | } |
| 301 | 301 | |
| ... | ... | @@ -318,8 +318,8 @@ pub fn sub(comptime T: type, a: T, b: T) (error{Overflow}!T) { |
| 318 | 318 | return if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer; |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | pub fn negate(x: var) !@typeOf(x) { | |
| 322 | return sub(@typeOf(x), 0, x); | |
| 321 | pub fn negate(x: var) !@TypeOf(x) { | |
| 322 | return sub(@TypeOf(x), 0, x); | |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | pub fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) !T { |
| ... | ... | @@ -333,7 +333,7 @@ pub fn shl(comptime T: type, a: T, shift_amt: var) T { |
| 333 | 333 | const abs_shift_amt = absCast(shift_amt); |
| 334 | 334 | const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else @intCast(Log2Int(T), abs_shift_amt); |
| 335 | 335 | |
| 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 | 337 | if (shift_amt < 0) { |
| 338 | 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 | 359 | const abs_shift_amt = absCast(shift_amt); |
| 360 | 360 | const casted_shift_amt = if (abs_shift_amt >= T.bit_count) return 0 else @intCast(Log2Int(T), abs_shift_amt); |
| 361 | 361 | |
| 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 | 363 | if (shift_amt >= 0) { |
| 364 | 364 | return a >> casted_shift_amt; |
| 365 | 365 | } else { |
| ... | ... | @@ -505,12 +505,12 @@ fn testOverflow() void { |
| 505 | 505 | testing.expect((shlExact(i32, 0b11, 4) catch unreachable) == 0b110000); |
| 506 | 506 | } |
| 507 | 507 | |
| 508 | pub fn absInt(x: var) !@typeOf(x) { | |
| 509 | const T = @typeOf(x); | |
| 508 | pub fn absInt(x: var) !@TypeOf(x) { | |
| 509 | const T = @TypeOf(x); | |
| 510 | 510 | comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer to absInt |
| 511 | 511 | comptime assert(T.is_signed); // must pass a signed integer to absInt |
| 512 | 512 | |
| 513 | if (x == minInt(@typeOf(x))) { | |
| 513 | if (x == minInt(@TypeOf(x))) { | |
| 514 | 514 | return error.Overflow; |
| 515 | 515 | } else { |
| 516 | 516 | @setRuntimeSafety(false); |
| ... | ... | @@ -654,16 +654,16 @@ fn testRem() void { |
| 654 | 654 | /// Returns the absolute value of the integer parameter. |
| 655 | 655 | /// Result is an unsigned integer. |
| 656 | 656 | pub fn absCast(x: var) t: { |
| 657 | if (@typeOf(x) == comptime_int) { | |
| 657 | if (@TypeOf(x) == comptime_int) { | |
| 658 | 658 | break :t comptime_int; |
| 659 | 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 | 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 | 667 | if (x >= 0) return @intCast(uint, x); |
| 668 | 668 | |
| 669 | 669 | return @intCast(uint, -(x + 1)) + 1; |
| ... | ... | @@ -671,23 +671,23 @@ pub fn absCast(x: var) t: { |
| 671 | 671 | |
| 672 | 672 | test "math.absCast" { |
| 673 | 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); | |
| 675 | 675 | |
| 676 | 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); | |
| 678 | 678 | |
| 679 | 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); | |
| 681 | 681 | |
| 682 | 682 | testing.expect(absCast(-999) == 999); |
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | /// Returns the negation of the integer parameter. |
| 686 | 686 | /// Result is a signed integer. |
| 687 | pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) { | |
| 688 | if (@typeOf(x).is_signed) return negate(x); | |
| 687 | pub fn negateCast(x: var) !@IntType(true, @TypeOf(x).bit_count) { | |
| 688 | if (@TypeOf(x).is_signed) return negate(x); | |
| 689 | 689 | |
| 690 | const int = @IntType(true, @typeOf(x).bit_count); | |
| 690 | const int = @IntType(true, @TypeOf(x).bit_count); | |
| 691 | 691 | if (x > -minInt(int)) return error.Overflow; |
| 692 | 692 | |
| 693 | 693 | if (x == -minInt(int)) return minInt(int); |
| ... | ... | @@ -697,10 +697,10 @@ pub fn negateCast(x: var) !@IntType(true, @typeOf(x).bit_count) { |
| 697 | 697 | |
| 698 | 698 | test "math.negateCast" { |
| 699 | 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); | |
| 701 | 701 | |
| 702 | 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); | |
| 704 | 704 | |
| 705 | 705 | testing.expectError(error.Overflow, negateCast(@as(u32, maxInt(i32) + 10))); |
| 706 | 706 | } |
| ... | ... | @@ -709,10 +709,10 @@ test "math.negateCast" { |
| 709 | 709 | /// return an error. |
| 710 | 710 | pub fn cast(comptime T: type, x: var) (error{Overflow}!T) { |
| 711 | 711 | comptime assert(@typeId(T) == builtin.TypeId.Int); // must pass an integer |
| 712 | comptime assert(@typeId(@typeOf(x)) == builtin.TypeId.Int); // must pass an integer | |
| 713 | if (maxInt(@typeOf(x)) > maxInt(T) and x > maxInt(T)) { | |
| 712 | comptime assert(@typeId(@TypeOf(x)) == builtin.TypeId.Int); // must pass an integer | |
| 713 | if (maxInt(@TypeOf(x)) > maxInt(T) and x > maxInt(T)) { | |
| 714 | 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 | 716 | return error.Overflow; |
| 717 | 717 | } else { |
| 718 | 718 | return @intCast(T, x); |
| ... | ... | @@ -726,13 +726,13 @@ test "math.cast" { |
| 726 | 726 | testing.expectError(error.Overflow, cast(u64, @as(i8, -1))); |
| 727 | 727 | |
| 728 | 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 | } |
| 731 | 731 | |
| 732 | 732 | pub const AlignCastError = error{UnalignedMemory}; |
| 733 | 733 | |
| 734 | 734 | /// Align cast a pointer but return an error if it's the wrong alignment |
| 735 | pub fn alignCast(comptime alignment: u29, ptr: var) AlignCastError!@typeOf(@alignCast(alignment, ptr)) { | |
| 735 | pub fn alignCast(comptime alignment: u29, ptr: var) AlignCastError!@TypeOf(@alignCast(alignment, ptr)) { | |
| 736 | 736 | const addr = @ptrToInt(ptr); |
| 737 | 737 | if (addr % alignment != 0) { |
| 738 | 738 | return error.UnalignedMemory; |
| ... | ... | @@ -858,7 +858,7 @@ test "std.math.log2_int_ceil" { |
| 858 | 858 | } |
| 859 | 859 | |
| 860 | 860 | pub fn lossyCast(comptime T: type, value: var) T { |
| 861 | switch (@typeInfo(@typeOf(value))) { | |
| 861 | switch (@typeInfo(@TypeOf(value))) { | |
| 862 | 862 | builtin.TypeId.Int => return @intToFloat(T, value), |
| 863 | 863 | builtin.TypeId.Float => return @floatCast(T, value), |
| 864 | 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 | 12 | /// |
| 13 | 13 | /// Special cases: |
| 14 | 14 | /// - acos(x) = nan if x < -1 or x > 1 |
| 15 | pub fn acos(x: var) @typeOf(x) { | |
| 16 | const T = @typeOf(x); | |
| 15 | pub fn acos(x: var) @TypeOf(x) { | |
| 16 | const T = @TypeOf(x); | |
| 17 | 17 | return switch (T) { |
| 18 | 18 | f32 => acos32(x), |
| 19 | 19 | f64 => acos64(x), |
lib/std/math/acosh.zig+2-2| ... | ... | @@ -14,8 +14,8 @@ const expect = std.testing.expect; |
| 14 | 14 | /// Special cases: |
| 15 | 15 | /// - acosh(x) = snan if x < 1 |
| 16 | 16 | /// - acosh(nan) = nan |
| 17 | pub fn acosh(x: var) @typeOf(x) { | |
| 18 | const T = @typeOf(x); | |
| 17 | pub fn acosh(x: var) @TypeOf(x) { | |
| 18 | const T = @TypeOf(x); | |
| 19 | 19 | return switch (T) { |
| 20 | 20 | f32 => acosh32(x), |
| 21 | 21 | f64 => acosh64(x), |
lib/std/math/asin.zig+2-2| ... | ... | @@ -13,8 +13,8 @@ const expect = std.testing.expect; |
| 13 | 13 | /// Special Cases: |
| 14 | 14 | /// - asin(+-0) = +-0 |
| 15 | 15 | /// - asin(x) = nan if x < -1 or x > 1 |
| 16 | pub fn asin(x: var) @typeOf(x) { | |
| 17 | const T = @typeOf(x); | |
| 16 | pub fn asin(x: var) @TypeOf(x) { | |
| 17 | const T = @TypeOf(x); | |
| 18 | 18 | return switch (T) { |
| 19 | 19 | f32 => asin32(x), |
| 20 | 20 | f64 => asin64(x), |
lib/std/math/asinh.zig+2-2| ... | ... | @@ -15,8 +15,8 @@ const maxInt = std.math.maxInt; |
| 15 | 15 | /// - asinh(+-0) = +-0 |
| 16 | 16 | /// - asinh(+-inf) = +-inf |
| 17 | 17 | /// - asinh(nan) = nan |
| 18 | pub fn asinh(x: var) @typeOf(x) { | |
| 19 | const T = @typeOf(x); | |
| 18 | pub fn asinh(x: var) @TypeOf(x) { | |
| 19 | const T = @TypeOf(x); | |
| 20 | 20 | return switch (T) { |
| 21 | 21 | f32 => asinh32(x), |
| 22 | 22 | f64 => asinh64(x), |
lib/std/math/atan.zig+2-2| ... | ... | @@ -13,8 +13,8 @@ const expect = std.testing.expect; |
| 13 | 13 | /// Special Cases: |
| 14 | 14 | /// - atan(+-0) = +-0 |
| 15 | 15 | /// - atan(+-inf) = +-pi/2 |
| 16 | pub fn atan(x: var) @typeOf(x) { | |
| 17 | const T = @typeOf(x); | |
| 16 | pub fn atan(x: var) @TypeOf(x) { | |
| 17 | const T = @TypeOf(x); | |
| 18 | 18 | return switch (T) { |
| 19 | 19 | f32 => atan32(x), |
| 20 | 20 | f64 => atan64(x), |
lib/std/math/atanh.zig+2-2| ... | ... | @@ -15,8 +15,8 @@ const maxInt = std.math.maxInt; |
| 15 | 15 | /// - atanh(+-1) = +-inf with signal |
| 16 | 16 | /// - atanh(x) = nan if |x| > 1 with signal |
| 17 | 17 | /// - atanh(nan) = nan |
| 18 | pub fn atanh(x: var) @typeOf(x) { | |
| 19 | const T = @typeOf(x); | |
| 18 | pub fn atanh(x: var) @TypeOf(x) { | |
| 19 | const T = @TypeOf(x); | |
| 20 | 20 | return switch (T) { |
| 21 | 21 | f32 => atanh_32(x), |
| 22 | 22 | f64 => atanh_64(x), |
lib/std/math/big/int.zig+2-2| ... | ... | @@ -268,7 +268,7 @@ pub const Int = struct { |
| 268 | 268 | /// Sets an Int to value. Value must be an primitive integer type. |
| 269 | 269 | pub fn set(self: *Int, value: var) Allocator.Error!void { |
| 270 | 270 | self.assertWritable(); |
| 271 | const T = @typeOf(value); | |
| 271 | const T = @TypeOf(value); | |
| 272 | 272 | |
| 273 | 273 | switch (@typeInfo(T)) { |
| 274 | 274 | TypeId.Int => |info| { |
| ... | ... | @@ -522,7 +522,7 @@ pub const Int = struct { |
| 522 | 522 | options: std.fmt.FormatOptions, |
| 523 | 523 | context: var, |
| 524 | 524 | comptime FmtError: type, |
| 525 | output: fn (@typeOf(context), []const u8) FmtError!void, | |
| 525 | output: fn (@TypeOf(context), []const u8) FmtError!void, | |
| 526 | 526 | ) FmtError!void { |
| 527 | 527 | self.assertWritable(); |
| 528 | 528 | // 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 | 14 | /// - cbrt(+-0) = +-0 |
| 15 | 15 | /// - cbrt(+-inf) = +-inf |
| 16 | 16 | /// - cbrt(nan) = nan |
| 17 | pub fn cbrt(x: var) @typeOf(x) { | |
| 18 | const T = @typeOf(x); | |
| 17 | pub fn cbrt(x: var) @TypeOf(x) { | |
| 18 | const T = @TypeOf(x); | |
| 19 | 19 | return switch (T) { |
| 20 | 20 | f32 => cbrt32(x), |
| 21 | 21 | f64 => cbrt64(x), |
lib/std/math/ceil.zig+2-2| ... | ... | @@ -15,8 +15,8 @@ const expect = std.testing.expect; |
| 15 | 15 | /// - ceil(+-0) = +-0 |
| 16 | 16 | /// - ceil(+-inf) = +-inf |
| 17 | 17 | /// - ceil(nan) = nan |
| 18 | pub fn ceil(x: var) @typeOf(x) { | |
| 19 | const T = @typeOf(x); | |
| 18 | pub fn ceil(x: var) @TypeOf(x) { | |
| 19 | const T = @TypeOf(x); | |
| 20 | 20 | return switch (T) { |
| 21 | 21 | f32 => ceil32(x), |
| 22 | 22 | f64 => ceil64(x), |
lib/std/math/complex/abs.zig+2-2| ... | ... | @@ -5,8 +5,8 @@ const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| 6 | 6 | |
| 7 | 7 | /// Returns the absolute value (modulus) of z. |
| 8 | pub fn abs(z: var) @typeOf(z.re) { | |
| 9 | const T = @typeOf(z.re); | |
| 8 | pub fn abs(z: var) @TypeOf(z.re) { | |
| 9 | const T = @TypeOf(z.re); | |
| 10 | 10 | return math.hypot(T, z.re, z.im); |
| 11 | 11 | } |
| 12 | 12 |
lib/std/math/complex/acos.zig+2-2| ... | ... | @@ -5,8 +5,8 @@ const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| 6 | 6 | |
| 7 | 7 | /// Returns the arc-cosine of z. |
| 8 | pub fn acos(z: var) Complex(@typeOf(z.re)) { | |
| 9 | const T = @typeOf(z.re); | |
| 8 | pub fn acos(z: var) Complex(@TypeOf(z.re)) { | |
| 9 | const T = @TypeOf(z.re); | |
| 10 | 10 | const q = cmath.asin(z); |
| 11 | 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 | 5 | const Complex = cmath.Complex; |
| 6 | 6 | |
| 7 | 7 | /// Returns the hyperbolic arc-cosine of z. |
| 8 | pub fn acosh(z: var) Complex(@typeOf(z.re)) { | |
| 9 | const T = @typeOf(z.re); | |
| 8 | pub fn acosh(z: var) Complex(@TypeOf(z.re)) { | |
| 9 | const T = @TypeOf(z.re); | |
| 10 | 10 | const q = cmath.acos(z); |
| 11 | 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 | 5 | const Complex = cmath.Complex; |
| 6 | 6 | |
| 7 | 7 | /// Returns the angular component (in radians) of z. |
| 8 | pub fn arg(z: var) @typeOf(z.re) { | |
| 9 | const T = @typeOf(z.re); | |
| 8 | pub fn arg(z: var) @TypeOf(z.re) { | |
| 9 | const T = @TypeOf(z.re); | |
| 10 | 10 | return math.atan2(T, z.im, z.re); |
| 11 | 11 | } |
| 12 | 12 |
lib/std/math/complex/asin.zig+2-2| ... | ... | @@ -5,8 +5,8 @@ const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| 6 | 6 | |
| 7 | 7 | // Returns the arc-sine of z. |
| 8 | pub fn asin(z: var) Complex(@typeOf(z.re)) { | |
| 9 | const T = @typeOf(z.re); | |
| 8 | pub fn asin(z: var) Complex(@TypeOf(z.re)) { | |
| 9 | const T = @TypeOf(z.re); | |
| 10 | 10 | const x = z.re; |
| 11 | 11 | const y = z.im; |
| 12 | 12 |
lib/std/math/complex/asinh.zig+2-2| ... | ... | @@ -5,8 +5,8 @@ const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| 6 | 6 | |
| 7 | 7 | /// Returns the hyperbolic arc-sine of z. |
| 8 | pub fn asinh(z: var) Complex(@typeOf(z.re)) { | |
| 9 | const T = @typeOf(z.re); | |
| 8 | pub fn asinh(z: var) Complex(@TypeOf(z.re)) { | |
| 9 | const T = @TypeOf(z.re); | |
| 10 | 10 | const q = Complex(T).new(-z.im, z.re); |
| 11 | 11 | const r = cmath.asin(q); |
| 12 | 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 | 12 | const Complex = cmath.Complex; |
| 13 | 13 | |
| 14 | 14 | /// Returns the arc-tangent of z. |
| 15 | pub fn atan(z: var) @typeOf(z) { | |
| 16 | const T = @typeOf(z.re); | |
| 15 | pub fn atan(z: var) @TypeOf(z) { | |
| 16 | const T = @TypeOf(z.re); | |
| 17 | 17 | return switch (T) { |
| 18 | 18 | f32 => atan32(z), |
| 19 | 19 | f64 => atan64(z), |
lib/std/math/complex/atanh.zig+2-2| ... | ... | @@ -5,8 +5,8 @@ const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| 6 | 6 | |
| 7 | 7 | /// Returns the hyperbolic arc-tangent of z. |
| 8 | pub fn atanh(z: var) Complex(@typeOf(z.re)) { | |
| 9 | const T = @typeOf(z.re); | |
| 8 | pub fn atanh(z: var) Complex(@TypeOf(z.re)) { | |
| 9 | const T = @TypeOf(z.re); | |
| 10 | 10 | const q = Complex(T).new(-z.im, z.re); |
| 11 | 11 | const r = cmath.atan(q); |
| 12 | 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 | 5 | const Complex = cmath.Complex; |
| 6 | 6 | |
| 7 | 7 | /// Returns the complex conjugate of z. |
| 8 | pub fn conj(z: var) Complex(@typeOf(z.re)) { | |
| 9 | const T = @typeOf(z.re); | |
| 8 | pub fn conj(z: var) Complex(@TypeOf(z.re)) { | |
| 9 | const T = @TypeOf(z.re); | |
| 10 | 10 | return Complex(T).new(z.re, -z.im); |
| 11 | 11 | } |
| 12 | 12 |
lib/std/math/complex/cos.zig+2-2| ... | ... | @@ -5,8 +5,8 @@ const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| 6 | 6 | |
| 7 | 7 | /// Returns the cosine of z. |
| 8 | pub fn cos(z: var) Complex(@typeOf(z.re)) { | |
| 9 | const T = @typeOf(z.re); | |
| 8 | pub fn cos(z: var) Complex(@TypeOf(z.re)) { | |
| 9 | const T = @TypeOf(z.re); | |
| 10 | 10 | const p = Complex(T).new(-z.im, z.re); |
| 11 | 11 | return cmath.cosh(p); |
| 12 | 12 | } |
lib/std/math/complex/cosh.zig+2-2| ... | ... | @@ -14,8 +14,8 @@ const Complex = cmath.Complex; |
| 14 | 14 | const ldexp_cexp = @import("ldexp.zig").ldexp_cexp; |
| 15 | 15 | |
| 16 | 16 | /// Returns the hyperbolic arc-cosine of z. |
| 17 | pub fn cosh(z: var) Complex(@typeOf(z.re)) { | |
| 18 | const T = @typeOf(z.re); | |
| 17 | pub fn cosh(z: var) Complex(@TypeOf(z.re)) { | |
| 18 | const T = @TypeOf(z.re); | |
| 19 | 19 | return switch (T) { |
| 20 | 20 | f32 => cosh32(z), |
| 21 | 21 | f64 => cosh64(z), |
lib/std/math/complex/exp.zig+2-2| ... | ... | @@ -14,8 +14,8 @@ const Complex = cmath.Complex; |
| 14 | 14 | const ldexp_cexp = @import("ldexp.zig").ldexp_cexp; |
| 15 | 15 | |
| 16 | 16 | /// Returns e raised to the power of z (e^z). |
| 17 | pub fn exp(z: var) @typeOf(z) { | |
| 18 | const T = @typeOf(z.re); | |
| 17 | pub fn exp(z: var) @TypeOf(z) { | |
| 18 | const T = @TypeOf(z.re); | |
| 19 | 19 | |
| 20 | 20 | return switch (T) { |
| 21 | 21 | f32 => exp32(z), |
lib/std/math/complex/ldexp.zig+2-2| ... | ... | @@ -11,8 +11,8 @@ const cmath = math.complex; |
| 11 | 11 | const Complex = cmath.Complex; |
| 12 | 12 | |
| 13 | 13 | /// Returns exp(z) scaled to avoid overflow. |
| 14 | pub fn ldexp_cexp(z: var, expt: i32) @typeOf(z) { | |
| 15 | const T = @typeOf(z.re); | |
| 14 | pub fn ldexp_cexp(z: var, expt: i32) @TypeOf(z) { | |
| 15 | const T = @TypeOf(z.re); | |
| 16 | 16 | |
| 17 | 17 | return switch (T) { |
| 18 | 18 | f32 => ldexp_cexp32(z, expt), |
lib/std/math/complex/log.zig+2-2| ... | ... | @@ -5,8 +5,8 @@ const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| 6 | 6 | |
| 7 | 7 | /// Returns the natural logarithm of z. |
| 8 | pub fn log(z: var) Complex(@typeOf(z.re)) { | |
| 9 | const T = @typeOf(z.re); | |
| 8 | pub fn log(z: var) Complex(@TypeOf(z.re)) { | |
| 9 | const T = @TypeOf(z.re); | |
| 10 | 10 | const r = cmath.abs(z); |
| 11 | 11 | const phi = cmath.arg(z); |
| 12 | 12 |
lib/std/math/complex/proj.zig+2-2| ... | ... | @@ -5,8 +5,8 @@ const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| 6 | 6 | |
| 7 | 7 | /// Returns the projection of z onto the riemann sphere. |
| 8 | pub fn proj(z: var) Complex(@typeOf(z.re)) { | |
| 9 | const T = @typeOf(z.re); | |
| 8 | pub fn proj(z: var) Complex(@TypeOf(z.re)) { | |
| 9 | const T = @TypeOf(z.re); | |
| 10 | 10 | |
| 11 | 11 | if (math.isInf(z.re) or math.isInf(z.im)) { |
| 12 | 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 | 5 | const Complex = cmath.Complex; |
| 6 | 6 | |
| 7 | 7 | /// Returns the sine of z. |
| 8 | pub fn sin(z: var) Complex(@typeOf(z.re)) { | |
| 9 | const T = @typeOf(z.re); | |
| 8 | pub fn sin(z: var) Complex(@TypeOf(z.re)) { | |
| 9 | const T = @TypeOf(z.re); | |
| 10 | 10 | const p = Complex(T).new(-z.im, z.re); |
| 11 | 11 | const q = cmath.sinh(p); |
| 12 | 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 | 14 | const ldexp_cexp = @import("ldexp.zig").ldexp_cexp; |
| 15 | 15 | |
| 16 | 16 | /// Returns the hyperbolic sine of z. |
| 17 | pub fn sinh(z: var) @typeOf(z) { | |
| 18 | const T = @typeOf(z.re); | |
| 17 | pub fn sinh(z: var) @TypeOf(z) { | |
| 18 | const T = @TypeOf(z.re); | |
| 19 | 19 | return switch (T) { |
| 20 | 20 | f32 => sinh32(z), |
| 21 | 21 | f64 => sinh64(z), |
lib/std/math/complex/sqrt.zig+2-2| ... | ... | @@ -12,8 +12,8 @@ const Complex = cmath.Complex; |
| 12 | 12 | |
| 13 | 13 | /// Returns the square root of z. The real and imaginary parts of the result have the same sign |
| 14 | 14 | /// as the imaginary part of z. |
| 15 | pub fn sqrt(z: var) @typeOf(z) { | |
| 16 | const T = @typeOf(z.re); | |
| 15 | pub fn sqrt(z: var) @TypeOf(z) { | |
| 16 | const T = @TypeOf(z.re); | |
| 17 | 17 | |
| 18 | 18 | return switch (T) { |
| 19 | 19 | f32 => sqrt32(z), |
lib/std/math/complex/tan.zig+2-2| ... | ... | @@ -5,8 +5,8 @@ const cmath = math.complex; |
| 5 | 5 | const Complex = cmath.Complex; |
| 6 | 6 | |
| 7 | 7 | /// Returns the tanget of z. |
| 8 | pub fn tan(z: var) Complex(@typeOf(z.re)) { | |
| 9 | const T = @typeOf(z.re); | |
| 8 | pub fn tan(z: var) Complex(@TypeOf(z.re)) { | |
| 9 | const T = @TypeOf(z.re); | |
| 10 | 10 | const q = Complex(T).new(-z.im, z.re); |
| 11 | 11 | const r = cmath.tanh(q); |
| 12 | 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 | 12 | const Complex = cmath.Complex; |
| 13 | 13 | |
| 14 | 14 | /// Returns the hyperbolic tangent of z. |
| 15 | pub fn tanh(z: var) @typeOf(z) { | |
| 16 | const T = @typeOf(z.re); | |
| 15 | pub fn tanh(z: var) @TypeOf(z) { | |
| 16 | const T = @TypeOf(z.re); | |
| 17 | 17 | return switch (T) { |
| 18 | 18 | f32 => tanh32(z), |
| 19 | 19 | f64 => tanh64(z), |
lib/std/math/cos.zig+2-2| ... | ... | @@ -13,8 +13,8 @@ const expect = std.testing.expect; |
| 13 | 13 | /// Special Cases: |
| 14 | 14 | /// - cos(+-inf) = nan |
| 15 | 15 | /// - cos(nan) = nan |
| 16 | pub fn cos(x: var) @typeOf(x) { | |
| 17 | const T = @typeOf(x); | |
| 16 | pub fn cos(x: var) @TypeOf(x) { | |
| 17 | const T = @TypeOf(x); | |
| 18 | 18 | return switch (T) { |
| 19 | 19 | f32 => cos_(f32, x), |
| 20 | 20 | f64 => cos_(f64, x), |
lib/std/math/cosh.zig+2-2| ... | ... | @@ -17,8 +17,8 @@ const maxInt = std.math.maxInt; |
| 17 | 17 | /// - cosh(+-0) = 1 |
| 18 | 18 | /// - cosh(+-inf) = +inf |
| 19 | 19 | /// - cosh(nan) = nan |
| 20 | pub fn cosh(x: var) @typeOf(x) { | |
| 21 | const T = @typeOf(x); | |
| 20 | pub fn cosh(x: var) @TypeOf(x) { | |
| 21 | const T = @TypeOf(x); | |
| 22 | 22 | return switch (T) { |
| 23 | 23 | f32 => cosh32(x), |
| 24 | 24 | f64 => cosh64(x), |
lib/std/math/exp.zig+2-2| ... | ... | @@ -14,8 +14,8 @@ const builtin = @import("builtin"); |
| 14 | 14 | /// Special Cases: |
| 15 | 15 | /// - exp(+inf) = +inf |
| 16 | 16 | /// - exp(nan) = nan |
| 17 | pub fn exp(x: var) @typeOf(x) { | |
| 18 | const T = @typeOf(x); | |
| 17 | pub fn exp(x: var) @TypeOf(x) { | |
| 18 | const T = @TypeOf(x); | |
| 19 | 19 | return switch (T) { |
| 20 | 20 | f32 => exp32(x), |
| 21 | 21 | f64 => exp64(x), |
lib/std/math/exp2.zig+2-2| ... | ... | @@ -13,8 +13,8 @@ const expect = std.testing.expect; |
| 13 | 13 | /// Special Cases: |
| 14 | 14 | /// - exp2(+inf) = +inf |
| 15 | 15 | /// - exp2(nan) = nan |
| 16 | pub fn exp2(x: var) @typeOf(x) { | |
| 17 | const T = @typeOf(x); | |
| 16 | pub fn exp2(x: var) @TypeOf(x) { | |
| 17 | const T = @TypeOf(x); | |
| 18 | 18 | return switch (T) { |
| 19 | 19 | f32 => exp2_32(x), |
| 20 | 20 | f64 => exp2_64(x), |
lib/std/math/expm1.zig+2-2| ... | ... | @@ -18,8 +18,8 @@ const expect = std.testing.expect; |
| 18 | 18 | /// - expm1(+inf) = +inf |
| 19 | 19 | /// - expm1(-inf) = -1 |
| 20 | 20 | /// - expm1(nan) = nan |
| 21 | pub fn expm1(x: var) @typeOf(x) { | |
| 22 | const T = @typeOf(x); | |
| 21 | pub fn expm1(x: var) @TypeOf(x) { | |
| 22 | const T = @TypeOf(x); | |
| 23 | 23 | return switch (T) { |
| 24 | 24 | f32 => expm1_32(x), |
| 25 | 25 | f64 => expm1_64(x), |
lib/std/math/expo2.zig+2-2| ... | ... | @@ -7,8 +7,8 @@ |
| 7 | 7 | const math = @import("../math.zig"); |
| 8 | 8 | |
| 9 | 9 | /// Returns exp(x) / 2 for x >= log(maxFloat(T)). |
| 10 | pub fn expo2(x: var) @typeOf(x) { | |
| 11 | const T = @typeOf(x); | |
| 10 | pub fn expo2(x: var) @TypeOf(x) { | |
| 11 | const T = @TypeOf(x); | |
| 12 | 12 | return switch (T) { |
| 13 | 13 | f32 => expo2f(x), |
| 14 | 14 | f64 => expo2d(x), |
lib/std/math/fabs.zig+2-2| ... | ... | @@ -14,8 +14,8 @@ const maxInt = std.math.maxInt; |
| 14 | 14 | /// Special Cases: |
| 15 | 15 | /// - fabs(+-inf) = +inf |
| 16 | 16 | /// - fabs(nan) = nan |
| 17 | pub fn fabs(x: var) @typeOf(x) { | |
| 18 | const T = @typeOf(x); | |
| 17 | pub fn fabs(x: var) @TypeOf(x) { | |
| 18 | const T = @TypeOf(x); | |
| 19 | 19 | return switch (T) { |
| 20 | 20 | f16 => fabs16(x), |
| 21 | 21 | f32 => fabs32(x), |
lib/std/math/floor.zig+2-2| ... | ... | @@ -15,8 +15,8 @@ const math = std.math; |
| 15 | 15 | /// - floor(+-0) = +-0 |
| 16 | 16 | /// - floor(+-inf) = +-inf |
| 17 | 17 | /// - floor(nan) = nan |
| 18 | pub fn floor(x: var) @typeOf(x) { | |
| 19 | const T = @typeOf(x); | |
| 18 | pub fn floor(x: var) @TypeOf(x) { | |
| 19 | const T = @TypeOf(x); | |
| 20 | 20 | return switch (T) { |
| 21 | 21 | f16 => floor16(x), |
| 22 | 22 | f32 => floor32(x), |
lib/std/math/frexp.zig+2-2| ... | ... | @@ -24,8 +24,8 @@ pub const frexp64_result = frexp_result(f64); |
| 24 | 24 | /// - frexp(+-0) = +-0, 0 |
| 25 | 25 | /// - frexp(+-inf) = +-inf, 0 |
| 26 | 26 | /// - frexp(nan) = nan, undefined |
| 27 | pub fn frexp(x: var) frexp_result(@typeOf(x)) { | |
| 28 | const T = @typeOf(x); | |
| 27 | pub fn frexp(x: var) frexp_result(@TypeOf(x)) { | |
| 28 | const T = @TypeOf(x); | |
| 29 | 29 | return switch (T) { |
| 30 | 30 | f32 => frexp32(x), |
| 31 | 31 | f64 => frexp64(x), |
lib/std/math/ilogb.zig+1-1| ... | ... | @@ -17,7 +17,7 @@ const minInt = std.math.minInt; |
| 17 | 17 | /// - ilogb(0) = maxInt(i32) |
| 18 | 18 | /// - ilogb(nan) = maxInt(i32) |
| 19 | 19 | pub fn ilogb(x: var) i32 { |
| 20 | const T = @typeOf(x); | |
| 20 | const T = @TypeOf(x); | |
| 21 | 21 | return switch (T) { |
| 22 | 22 | f32 => ilogb32(x), |
| 23 | 23 | f64 => ilogb64(x), |
lib/std/math/isfinite.zig+1-1| ... | ... | @@ -5,7 +5,7 @@ const maxInt = std.math.maxInt; |
| 5 | 5 | |
| 6 | 6 | /// Returns whether x is a finite value. |
| 7 | 7 | pub fn isFinite(x: var) bool { |
| 8 | const T = @typeOf(x); | |
| 8 | const T = @TypeOf(x); | |
| 9 | 9 | switch (T) { |
| 10 | 10 | f16 => { |
| 11 | 11 | const bits = @bitCast(u16, x); |
lib/std/math/isinf.zig+3-3| ... | ... | @@ -5,7 +5,7 @@ const maxInt = std.math.maxInt; |
| 5 | 5 | |
| 6 | 6 | /// Returns whether x is an infinity, ignoring sign. |
| 7 | 7 | pub fn isInf(x: var) bool { |
| 8 | const T = @typeOf(x); | |
| 8 | const T = @TypeOf(x); | |
| 9 | 9 | switch (T) { |
| 10 | 10 | f16 => { |
| 11 | 11 | const bits = @bitCast(u16, x); |
| ... | ... | @@ -31,7 +31,7 @@ pub fn isInf(x: var) bool { |
| 31 | 31 | |
| 32 | 32 | /// Returns whether x is an infinity with a positive sign. |
| 33 | 33 | pub fn isPositiveInf(x: var) bool { |
| 34 | const T = @typeOf(x); | |
| 34 | const T = @TypeOf(x); | |
| 35 | 35 | switch (T) { |
| 36 | 36 | f16 => { |
| 37 | 37 | return @bitCast(u16, x) == 0x7C00; |
| ... | ... | @@ -53,7 +53,7 @@ pub fn isPositiveInf(x: var) bool { |
| 53 | 53 | |
| 54 | 54 | /// Returns whether x is an infinity with a negative sign. |
| 55 | 55 | pub fn isNegativeInf(x: var) bool { |
| 56 | const T = @typeOf(x); | |
| 56 | const T = @TypeOf(x); | |
| 57 | 57 | switch (T) { |
| 58 | 58 | f16 => { |
| 59 | 59 | return @bitCast(u16, x) == 0xFC00; |
lib/std/math/isnormal.zig+1-1| ... | ... | @@ -5,7 +5,7 @@ const maxInt = std.math.maxInt; |
| 5 | 5 | |
| 6 | 6 | // Returns whether x has a normalized representation (i.e. integer part of mantissa is 1). |
| 7 | 7 | pub fn isNormal(x: var) bool { |
| 8 | const T = @typeOf(x); | |
| 8 | const T = @TypeOf(x); | |
| 9 | 9 | switch (T) { |
| 10 | 10 | f16 => { |
| 11 | 11 | const bits = @bitCast(u16, x); |
lib/std/math/ln.zig+4-4| ... | ... | @@ -17,11 +17,11 @@ const TypeId = builtin.TypeId; |
| 17 | 17 | /// - ln(0) = -inf |
| 18 | 18 | /// - ln(x) = nan if x < 0 |
| 19 | 19 | /// - ln(nan) = nan |
| 20 | pub fn ln(x: var) @typeOf(x) { | |
| 21 | const T = @typeOf(x); | |
| 20 | pub fn ln(x: var) @TypeOf(x) { | |
| 21 | const T = @TypeOf(x); | |
| 22 | 22 | switch (@typeId(T)) { |
| 23 | 23 | TypeId.ComptimeFloat => { |
| 24 | return @typeOf(1.0)(ln_64(x)); | |
| 24 | return @TypeOf(1.0)(ln_64(x)); | |
| 25 | 25 | }, |
| 26 | 26 | TypeId.Float => { |
| 27 | 27 | return switch (T) { |
| ... | ... | @@ -31,7 +31,7 @@ pub fn ln(x: var) @typeOf(x) { |
| 31 | 31 | }; |
| 32 | 32 | }, |
| 33 | 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 | 36 | TypeId.Int => { |
| 37 | 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 | 23 | const float_base = math.lossyCast(f64, base); |
| 24 | 24 | switch (@typeId(T)) { |
| 25 | 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 | 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 | 31 | builtin.TypeId.Int => { |
| 32 | 32 | // 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 | 18 | /// - log10(0) = -inf |
| 19 | 19 | /// - log10(x) = nan if x < 0 |
| 20 | 20 | /// - log10(nan) = nan |
| 21 | pub fn log10(x: var) @typeOf(x) { | |
| 22 | const T = @typeOf(x); | |
| 21 | pub fn log10(x: var) @TypeOf(x) { | |
| 22 | const T = @TypeOf(x); | |
| 23 | 23 | switch (@typeId(T)) { |
| 24 | 24 | TypeId.ComptimeFloat => { |
| 25 | return @typeOf(1.0)(log10_64(x)); | |
| 25 | return @TypeOf(1.0)(log10_64(x)); | |
| 26 | 26 | }, |
| 27 | 27 | TypeId.Float => { |
| 28 | 28 | return switch (T) { |
| ... | ... | @@ -32,7 +32,7 @@ pub fn log10(x: var) @typeOf(x) { |
| 32 | 32 | }; |
| 33 | 33 | }, |
| 34 | 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 | 37 | TypeId.Int => { |
| 38 | 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 | 17 | /// - log1p(-1) = -inf |
| 18 | 18 | /// - log1p(x) = nan if x < -1 |
| 19 | 19 | /// - log1p(nan) = nan |
| 20 | pub fn log1p(x: var) @typeOf(x) { | |
| 21 | const T = @typeOf(x); | |
| 20 | pub fn log1p(x: var) @TypeOf(x) { | |
| 21 | const T = @TypeOf(x); | |
| 22 | 22 | return switch (T) { |
| 23 | 23 | f32 => log1p_32(x), |
| 24 | 24 | f64 => log1p_64(x), |
lib/std/math/log2.zig+3-3| ... | ... | @@ -18,11 +18,11 @@ const maxInt = std.math.maxInt; |
| 18 | 18 | /// - log2(0) = -inf |
| 19 | 19 | /// - log2(x) = nan if x < 0 |
| 20 | 20 | /// - log2(nan) = nan |
| 21 | pub fn log2(x: var) @typeOf(x) { | |
| 22 | const T = @typeOf(x); | |
| 21 | pub fn log2(x: var) @TypeOf(x) { | |
| 22 | const T = @TypeOf(x); | |
| 23 | 23 | switch (@typeId(T)) { |
| 24 | 24 | TypeId.ComptimeFloat => { |
| 25 | return @typeOf(1.0)(log2_64(x)); | |
| 25 | return @TypeOf(1.0)(log2_64(x)); | |
| 26 | 26 | }, |
| 27 | 27 | TypeId.Float => { |
| 28 | 28 | return switch (T) { |
lib/std/math/modf.zig+2-2| ... | ... | @@ -24,8 +24,8 @@ pub const modf64_result = modf_result(f64); |
| 24 | 24 | /// Special Cases: |
| 25 | 25 | /// - modf(+-inf) = +-inf, nan |
| 26 | 26 | /// - modf(nan) = nan, nan |
| 27 | pub fn modf(x: var) modf_result(@typeOf(x)) { | |
| 28 | const T = @typeOf(x); | |
| 27 | pub fn modf(x: var) modf_result(@TypeOf(x)) { | |
| 28 | const T = @TypeOf(x); | |
| 29 | 29 | return switch (T) { |
| 30 | 30 | f32 => modf32(x), |
| 31 | 31 | f64 => modf64(x), |
lib/std/math/round.zig+2-2| ... | ... | @@ -15,8 +15,8 @@ const math = std.math; |
| 15 | 15 | /// - round(+-0) = +-0 |
| 16 | 16 | /// - round(+-inf) = +-inf |
| 17 | 17 | /// - round(nan) = nan |
| 18 | pub fn round(x: var) @typeOf(x) { | |
| 19 | const T = @typeOf(x); | |
| 18 | pub fn round(x: var) @TypeOf(x) { | |
| 19 | const T = @TypeOf(x); | |
| 20 | 20 | return switch (T) { |
| 21 | 21 | f32 => round32(x), |
| 22 | 22 | f64 => round64(x), |
lib/std/math/scalbn.zig+2-2| ... | ... | @@ -9,8 +9,8 @@ const math = std.math; |
| 9 | 9 | const expect = std.testing.expect; |
| 10 | 10 | |
| 11 | 11 | /// Returns x * 2^n. |
| 12 | pub fn scalbn(x: var, n: i32) @typeOf(x) { | |
| 13 | const T = @typeOf(x); | |
| 12 | pub fn scalbn(x: var, n: i32) @TypeOf(x) { | |
| 13 | const T = @TypeOf(x); | |
| 14 | 14 | return switch (T) { |
| 15 | 15 | f32 => scalbn32(x, n), |
| 16 | 16 | f64 => scalbn64(x, n), |
lib/std/math/signbit.zig+1-1| ... | ... | @@ -4,7 +4,7 @@ const expect = std.testing.expect; |
| 4 | 4 | |
| 5 | 5 | /// Returns whether x is negative or negative 0. |
| 6 | 6 | pub fn signbit(x: var) bool { |
| 7 | const T = @typeOf(x); | |
| 7 | const T = @TypeOf(x); | |
| 8 | 8 | return switch (T) { |
| 9 | 9 | f16 => signbit16(x), |
| 10 | 10 | f32 => signbit32(x), |
lib/std/math/sin.zig+2-2| ... | ... | @@ -14,8 +14,8 @@ const expect = std.testing.expect; |
| 14 | 14 | /// - sin(+-0) = +-0 |
| 15 | 15 | /// - sin(+-inf) = nan |
| 16 | 16 | /// - sin(nan) = nan |
| 17 | pub fn sin(x: var) @typeOf(x) { | |
| 18 | const T = @typeOf(x); | |
| 17 | pub fn sin(x: var) @TypeOf(x) { | |
| 18 | const T = @TypeOf(x); | |
| 19 | 19 | return switch (T) { |
| 20 | 20 | f32 => sin_(T, x), |
| 21 | 21 | f64 => sin_(T, x), |
lib/std/math/sinh.zig+2-2| ... | ... | @@ -17,8 +17,8 @@ const maxInt = std.math.maxInt; |
| 17 | 17 | /// - sinh(+-0) = +-0 |
| 18 | 18 | /// - sinh(+-inf) = +-inf |
| 19 | 19 | /// - sinh(nan) = nan |
| 20 | pub fn sinh(x: var) @typeOf(x) { | |
| 21 | const T = @typeOf(x); | |
| 20 | pub fn sinh(x: var) @TypeOf(x) { | |
| 21 | const T = @TypeOf(x); | |
| 22 | 22 | return switch (T) { |
| 23 | 23 | f32 => sinh32(x), |
| 24 | 24 | f64 => sinh64(x), |
lib/std/math/sqrt.zig+2-2| ... | ... | @@ -12,8 +12,8 @@ const maxInt = std.math.maxInt; |
| 12 | 12 | /// - sqrt(+-0) = +-0 |
| 13 | 13 | /// - sqrt(x) = nan if x < 0 |
| 14 | 14 | /// - sqrt(nan) = nan |
| 15 | pub 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); | |
| 15 | pub 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); | |
| 17 | 17 | switch (@typeId(T)) { |
| 18 | 18 | TypeId.ComptimeFloat => return @as(T, @sqrt(f64, x)), // TODO upgrade to f128 |
| 19 | 19 | TypeId.Float => return @sqrt(T, x), |
lib/std/math/tan.zig+2-2| ... | ... | @@ -14,8 +14,8 @@ const expect = std.testing.expect; |
| 14 | 14 | /// - tan(+-0) = +-0 |
| 15 | 15 | /// - tan(+-inf) = nan |
| 16 | 16 | /// - tan(nan) = nan |
| 17 | pub fn tan(x: var) @typeOf(x) { | |
| 18 | const T = @typeOf(x); | |
| 17 | pub fn tan(x: var) @TypeOf(x) { | |
| 18 | const T = @TypeOf(x); | |
| 19 | 19 | return switch (T) { |
| 20 | 20 | f32 => tan_(f32, x), |
| 21 | 21 | f64 => tan_(f64, x), |
lib/std/math/tanh.zig+2-2| ... | ... | @@ -17,8 +17,8 @@ const maxInt = std.math.maxInt; |
| 17 | 17 | /// - sinh(+-0) = +-0 |
| 18 | 18 | /// - sinh(+-inf) = +-1 |
| 19 | 19 | /// - sinh(nan) = nan |
| 20 | pub fn tanh(x: var) @typeOf(x) { | |
| 21 | const T = @typeOf(x); | |
| 20 | pub fn tanh(x: var) @TypeOf(x) { | |
| 21 | const T = @TypeOf(x); | |
| 22 | 22 | return switch (T) { |
| 23 | 23 | f32 => tanh32(x), |
| 24 | 24 | f64 => tanh64(x), |
lib/std/math/trunc.zig+2-2| ... | ... | @@ -15,8 +15,8 @@ const maxInt = std.math.maxInt; |
| 15 | 15 | /// - trunc(+-0) = +-0 |
| 16 | 16 | /// - trunc(+-inf) = +-inf |
| 17 | 17 | /// - trunc(nan) = nan |
| 18 | pub fn trunc(x: var) @typeOf(x) { | |
| 19 | const T = @typeOf(x); | |
| 18 | pub fn trunc(x: var) @TypeOf(x) { | |
| 19 | const T = @TypeOf(x); | |
| 20 | 20 | return switch (T) { |
| 21 | 21 | f32 => trunc32(x), |
| 22 | 22 | f64 => trunc64(x), |
lib/std/mem.zig+18-18| ... | ... | @@ -86,7 +86,7 @@ pub const Allocator = struct { |
| 86 | 86 | /// `ptr` should be the return value of `create`, or otherwise |
| 87 | 87 | /// have the same address and alignment property. |
| 88 | 88 | pub fn destroy(self: *Allocator, ptr: var) void { |
| 89 | const T = @typeOf(ptr).Child; | |
| 89 | const T = @TypeOf(ptr).Child; | |
| 90 | 90 | if (@sizeOf(T) == 0) return; |
| 91 | 91 | const non_const_ptr = @intToPtr([*]u8, @ptrToInt(ptr)); |
| 92 | 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 | 147 | /// If you need guaranteed success, call `shrink`. |
| 148 | 148 | /// If `new_n` is 0, this is the same as `free` and it always succeeds. |
| 149 | 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 | 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 | 154 | return self.alignedRealloc(old_mem, old_alignment, new_n); |
| 155 | 155 | } |
| 156 | 156 | |
| ... | ... | @@ -162,8 +162,8 @@ pub const Allocator = struct { |
| 162 | 162 | old_mem: var, |
| 163 | 163 | comptime new_alignment: u29, |
| 164 | 164 | new_n: usize, |
| 165 | ) Error![]align(new_alignment) @typeInfo(@typeOf(old_mem)).Pointer.child { | |
| 166 | const Slice = @typeInfo(@typeOf(old_mem)).Pointer; | |
| 165 | ) Error![]align(new_alignment) @typeInfo(@TypeOf(old_mem)).Pointer.child { | |
| 166 | const Slice = @typeInfo(@TypeOf(old_mem)).Pointer; | |
| 167 | 167 | const T = Slice.child; |
| 168 | 168 | if (old_mem.len == 0) { |
| 169 | 169 | return self.alignedAlloc(T, new_alignment, new_n); |
| ... | ... | @@ -189,10 +189,10 @@ pub const Allocator = struct { |
| 189 | 189 | /// Returned slice has same alignment as old_mem. |
| 190 | 190 | /// Shrinking to 0 is the same as calling `free`. |
| 191 | 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 | 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 | 196 | return self.alignedShrink(old_mem, old_alignment, new_n); |
| 197 | 197 | } |
| 198 | 198 | |
| ... | ... | @@ -204,8 +204,8 @@ pub const Allocator = struct { |
| 204 | 204 | old_mem: var, |
| 205 | 205 | comptime new_alignment: u29, |
| 206 | 206 | new_n: usize, |
| 207 | ) []align(new_alignment) @typeInfo(@typeOf(old_mem)).Pointer.child { | |
| 208 | const Slice = @typeInfo(@typeOf(old_mem)).Pointer; | |
| 207 | ) []align(new_alignment) @typeInfo(@TypeOf(old_mem)).Pointer.child { | |
| 208 | const Slice = @typeInfo(@TypeOf(old_mem)).Pointer; | |
| 209 | 209 | const T = Slice.child; |
| 210 | 210 | |
| 211 | 211 | if (new_n == 0) { |
| ... | ... | @@ -229,7 +229,7 @@ pub const Allocator = struct { |
| 229 | 229 | /// Free an array allocated with `alloc`. To free a single item, |
| 230 | 230 | /// see `destroy`. |
| 231 | 231 | pub fn free(self: *Allocator, memory: var) void { |
| 232 | const Slice = @typeInfo(@typeOf(memory)).Pointer; | |
| 232 | const Slice = @typeInfo(@TypeOf(memory)).Pointer; | |
| 233 | 233 | const bytes = @sliceToBytes(memory); |
| 234 | 234 | if (bytes.len == 0) return; |
| 235 | 235 | const non_const_ptr = @intToPtr([*]u8, @ptrToInt(bytes.ptr)); |
| ... | ... | @@ -1323,8 +1323,8 @@ fn AsBytesReturnType(comptime P: type) type { |
| 1323 | 1323 | } |
| 1324 | 1324 | |
| 1325 | 1325 | ///Given a pointer to a single item, returns a slice of the underlying bytes, preserving constness. |
| 1326 | pub fn asBytes(ptr: var) AsBytesReturnType(@typeOf(ptr)) { | |
| 1327 | const P = @typeOf(ptr); | |
| 1326 | pub fn asBytes(ptr: var) AsBytesReturnType(@TypeOf(ptr)) { | |
| 1327 | const P = @TypeOf(ptr); | |
| 1328 | 1328 | return @ptrCast(AsBytesReturnType(P), ptr); |
| 1329 | 1329 | } |
| 1330 | 1330 | |
| ... | ... | @@ -1363,7 +1363,7 @@ test "asBytes" { |
| 1363 | 1363 | } |
| 1364 | 1364 | |
| 1365 | 1365 | ///Given any value, returns a copy of its bytes in an array. |
| 1366 | pub fn toBytes(value: var) [@sizeOf(@typeOf(value))]u8 { | |
| 1366 | pub fn toBytes(value: var) [@sizeOf(@TypeOf(value))]u8 { | |
| 1367 | 1367 | return asBytes(&value).*; |
| 1368 | 1368 | } |
| 1369 | 1369 | |
| ... | ... | @@ -1397,8 +1397,8 @@ fn BytesAsValueReturnType(comptime T: type, comptime B: type) type { |
| 1397 | 1397 | |
| 1398 | 1398 | ///Given a pointer to an array of bytes, returns a pointer to a value of the specified type |
| 1399 | 1399 | /// backed by those bytes, preserving constness. |
| 1400 | pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @typeOf(bytes)) { | |
| 1401 | return @ptrCast(BytesAsValueReturnType(T, @typeOf(bytes)), bytes); | |
| 1400 | pub fn bytesAsValue(comptime T: type, bytes: var) BytesAsValueReturnType(T, @TypeOf(bytes)) { | |
| 1401 | return @ptrCast(BytesAsValueReturnType(T, @TypeOf(bytes)), bytes); | |
| 1402 | 1402 | } |
| 1403 | 1403 | |
| 1404 | 1404 | test "bytesAsValue" { |
| ... | ... | @@ -1460,11 +1460,11 @@ fn SubArrayPtrReturnType(comptime T: type, comptime length: usize) type { |
| 1460 | 1460 | } |
| 1461 | 1461 | |
| 1462 | 1462 | ///Given a pointer to an array, returns a pointer to a portion of that array, preserving constness. |
| 1463 | pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubArrayPtrReturnType(@typeOf(ptr), length) { | |
| 1463 | pub fn subArrayPtr(ptr: var, comptime start: usize, comptime length: usize) SubArrayPtrReturnType(@TypeOf(ptr), length) { | |
| 1464 | 1464 | assert(start + length <= ptr.*.len); |
| 1465 | 1465 | |
| 1466 | const ReturnType = SubArrayPtrReturnType(@typeOf(ptr), length); | |
| 1467 | const T = meta.Child(meta.Child(@typeOf(ptr))); | |
| 1466 | const ReturnType = SubArrayPtrReturnType(@TypeOf(ptr), length); | |
| 1467 | const T = meta.Child(meta.Child(@TypeOf(ptr))); | |
| 1468 | 1468 | return @ptrCast(ReturnType, &ptr[start]); |
| 1469 | 1469 | } |
| 1470 | 1470 |
lib/std/meta.zig+7-7| ... | ... | @@ -11,7 +11,7 @@ const TypeId = builtin.TypeId; |
| 11 | 11 | const TypeInfo = builtin.TypeInfo; |
| 12 | 12 | |
| 13 | 13 | pub fn tagName(v: var) []const u8 { |
| 14 | const T = @typeOf(v); | |
| 14 | const T = @TypeOf(v); | |
| 15 | 15 | switch (@typeInfo(T)) { |
| 16 | 16 | TypeId.ErrorSet => return @errorName(v), |
| 17 | 17 | else => return @tagName(v), |
| ... | ... | @@ -339,8 +339,8 @@ test "std.meta.TagType" { |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | ///Returns the active tag of a tagged union |
| 342 | pub fn activeTag(u: var) @TagType(@typeOf(u)) { | |
| 343 | const T = @typeOf(u); | |
| 342 | pub fn activeTag(u: var) @TagType(@TypeOf(u)) { | |
| 343 | const T = @TypeOf(u); | |
| 344 | 344 | return @as(@TagType(T), u); |
| 345 | 345 | } |
| 346 | 346 | |
| ... | ... | @@ -365,7 +365,7 @@ test "std.meta.activeTag" { |
| 365 | 365 | ///Given a tagged union type, and an enum, return the type of the union |
| 366 | 366 | /// field corresponding to the enum tag. |
| 367 | 367 | pub fn TagPayloadType(comptime U: type, tag: var) type { |
| 368 | const Tag = @typeOf(tag); | |
| 368 | const Tag = @TypeOf(tag); | |
| 369 | 369 | testing.expect(trait.is(builtin.TypeId.Union)(U)); |
| 370 | 370 | testing.expect(trait.is(builtin.TypeId.Enum)(Tag)); |
| 371 | 371 | |
| ... | ... | @@ -386,13 +386,13 @@ test "std.meta.TagPayloadType" { |
| 386 | 386 | }; |
| 387 | 387 | const MovedEvent = TagPayloadType(Event, Event.Moved); |
| 388 | 388 | var e: Event = undefined; |
| 389 | testing.expect(MovedEvent == @typeOf(e.Moved)); | |
| 389 | testing.expect(MovedEvent == @TypeOf(e.Moved)); | |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | ///Compares two of any type for equality. Containers are compared on a field-by-field basis, |
| 393 | 393 | /// where possible. Pointers are not followed. |
| 394 | pub fn eql(a: var, b: @typeOf(a)) bool { | |
| 395 | const T = @typeOf(a); | |
| 394 | pub fn eql(a: var, b: @TypeOf(a)) bool { | |
| 395 | const T = @TypeOf(a); | |
| 396 | 396 | |
| 397 | 397 | switch (@typeId(T)) { |
| 398 | 398 | builtin.TypeId.Struct => { |
lib/std/meta/trait.zig+21-21| ... | ... | @@ -13,7 +13,7 @@ fn traitFnWorkaround(comptime T: type) bool { |
| 13 | 13 | return false; |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | pub const TraitFn = @typeOf(traitFnWorkaround); | |
| 16 | pub const TraitFn = @TypeOf(traitFnWorkaround); | |
| 17 | 17 | /// |
| 18 | 18 | |
| 19 | 19 | //////Trait generators |
| ... | ... | @@ -61,7 +61,7 @@ pub fn hasFn(comptime name: []const u8) TraitFn { |
| 61 | 61 | pub fn trait(comptime T: type) bool { |
| 62 | 62 | if (!comptime isContainer(T)) return false; |
| 63 | 63 | if (!comptime @hasDecl(T, name)) return false; |
| 64 | const DeclType = @typeOf(@field(T, name)); | |
| 64 | const DeclType = @TypeOf(@field(T, name)); | |
| 65 | 65 | const decl_type_id = @typeId(DeclType); |
| 66 | 66 | return decl_type_id == builtin.TypeId.Fn; |
| 67 | 67 | } |
| ... | ... | @@ -236,9 +236,9 @@ pub fn isSingleItemPtr(comptime T: type) bool { |
| 236 | 236 | |
| 237 | 237 | test "std.meta.trait.isSingleItemPtr" { |
| 238 | 238 | const array = [_]u8{0} ** 10; |
| 239 | testing.expect(isSingleItemPtr(@typeOf(&array[0]))); | |
| 240 | testing.expect(!isSingleItemPtr(@typeOf(array))); | |
| 241 | testing.expect(!isSingleItemPtr(@typeOf(array[0..1]))); | |
| 239 | testing.expect(isSingleItemPtr(@TypeOf(&array[0]))); | |
| 240 | testing.expect(!isSingleItemPtr(@TypeOf(array))); | |
| 241 | testing.expect(!isSingleItemPtr(@TypeOf(array[0..1]))); | |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /// |
| ... | ... | @@ -253,9 +253,9 @@ pub fn isManyItemPtr(comptime T: type) bool { |
| 253 | 253 | test "std.meta.trait.isManyItemPtr" { |
| 254 | 254 | const array = [_]u8{0} ** 10; |
| 255 | 255 | const mip = @ptrCast([*]const u8, &array[0]); |
| 256 | testing.expect(isManyItemPtr(@typeOf(mip))); | |
| 257 | testing.expect(!isManyItemPtr(@typeOf(array))); | |
| 258 | testing.expect(!isManyItemPtr(@typeOf(array[0..1]))); | |
| 256 | testing.expect(isManyItemPtr(@TypeOf(mip))); | |
| 257 | testing.expect(!isManyItemPtr(@TypeOf(array))); | |
| 258 | testing.expect(!isManyItemPtr(@TypeOf(array[0..1]))); | |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /// |
| ... | ... | @@ -269,9 +269,9 @@ pub fn isSlice(comptime T: type) bool { |
| 269 | 269 | |
| 270 | 270 | test "std.meta.trait.isSlice" { |
| 271 | 271 | const array = [_]u8{0} ** 10; |
| 272 | testing.expect(isSlice(@typeOf(array[0..]))); | |
| 273 | testing.expect(!isSlice(@typeOf(array))); | |
| 274 | testing.expect(!isSlice(@typeOf(&array[0]))); | |
| 272 | testing.expect(isSlice(@TypeOf(array[0..]))); | |
| 273 | testing.expect(!isSlice(@TypeOf(array))); | |
| 274 | testing.expect(!isSlice(@TypeOf(&array[0]))); | |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /// |
| ... | ... | @@ -291,10 +291,10 @@ test "std.meta.trait.isIndexable" { |
| 291 | 291 | const array = [_]u8{0} ** 10; |
| 292 | 292 | const slice = array[0..]; |
| 293 | 293 | |
| 294 | testing.expect(isIndexable(@typeOf(array))); | |
| 295 | testing.expect(isIndexable(@typeOf(&array))); | |
| 296 | testing.expect(isIndexable(@typeOf(slice))); | |
| 297 | testing.expect(!isIndexable(meta.Child(@typeOf(slice)))); | |
| 294 | testing.expect(isIndexable(@TypeOf(array))); | |
| 295 | testing.expect(isIndexable(@TypeOf(&array))); | |
| 296 | testing.expect(isIndexable(@TypeOf(slice))); | |
| 297 | testing.expect(!isIndexable(meta.Child(@TypeOf(slice)))); | |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /// |
| ... | ... | @@ -313,8 +313,8 @@ test "std.meta.trait.isNumber" { |
| 313 | 313 | testing.expect(isNumber(u32)); |
| 314 | 314 | testing.expect(isNumber(f32)); |
| 315 | 315 | testing.expect(isNumber(u64)); |
| 316 | testing.expect(isNumber(@typeOf(102))); | |
| 317 | testing.expect(isNumber(@typeOf(102.123))); | |
| 316 | testing.expect(isNumber(@TypeOf(102))); | |
| 317 | testing.expect(isNumber(@TypeOf(102.123))); | |
| 318 | 318 | testing.expect(!isNumber([]u8)); |
| 319 | 319 | testing.expect(!isNumber(NotANumber)); |
| 320 | 320 | } |
| ... | ... | @@ -328,10 +328,10 @@ pub fn isConstPtr(comptime T: type) bool { |
| 328 | 328 | test "std.meta.trait.isConstPtr" { |
| 329 | 329 | var t = @as(u8, 0); |
| 330 | 330 | const c = @as(u8, 0); |
| 331 | testing.expect(isConstPtr(*const @typeOf(t))); | |
| 332 | testing.expect(isConstPtr(@typeOf(&c))); | |
| 333 | testing.expect(!isConstPtr(*@typeOf(t))); | |
| 334 | testing.expect(!isConstPtr(@typeOf(6))); | |
| 331 | testing.expect(isConstPtr(*const @TypeOf(t))); | |
| 332 | testing.expect(isConstPtr(@TypeOf(&c))); | |
| 333 | testing.expect(!isConstPtr(*@TypeOf(t))); | |
| 334 | testing.expect(!isConstPtr(@TypeOf(6))); | |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | pub fn isContainer(comptime T: type) bool { |
lib/std/mutex.zig+1-1| ... | ... | @@ -11,7 +11,7 @@ const ResetEvent = std.ResetEvent; |
| 11 | 11 | /// no-ops. In single threaded debug mode, there is deadlock detection. |
| 12 | 12 | pub const Mutex = if (builtin.single_threaded) |
| 13 | 13 | struct { |
| 14 | lock: @typeOf(lock_init), | |
| 14 | lock: @TypeOf(lock_init), | |
| 15 | 15 | |
| 16 | 16 | const lock_init = if (std.debug.runtime_safety) false else {}; |
| 17 | 17 |
lib/std/net.zig+1-1| ... | ... | @@ -271,7 +271,7 @@ pub const Address = extern union { |
| 271 | 271 | options: std.fmt.FormatOptions, |
| 272 | 272 | context: var, |
| 273 | 273 | comptime Errors: type, |
| 274 | output: fn (@typeOf(context), []const u8) Errors!void, | |
| 274 | output: fn (@TypeOf(context), []const u8) Errors!void, | |
| 275 | 275 | ) !void { |
| 276 | 276 | switch (self.any.family) { |
| 277 | 277 | os.AF_INET => { |
lib/std/os.zig+1-1| ... | ... | @@ -2974,7 +2974,7 @@ pub fn res_mkquery( |
| 2974 | 2974 | // Make a reasonably unpredictable id |
| 2975 | 2975 | var ts: timespec = undefined; |
| 2976 | 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 | 2978 | const unsec = @bitCast(UInt, ts.tv_nsec); |
| 2979 | 2979 | const id = @truncate(u32, unsec + unsec / 65536); |
| 2980 | 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 | 706 | .restorer = @ptrCast(extern fn () void, restorer_fn), |
| 707 | 707 | }; |
| 708 | 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 | 710 | @memcpy(@ptrCast([*]u8, &ksa.mask), @ptrCast([*]const u8, &act.mask), ksa_mask_size); |
| 711 | 711 | const result = syscall4(SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), ksa_mask_size); |
| 712 | 712 | const err = getErrno(result); |
| ... | ... | @@ -786,7 +786,7 @@ pub fn sendmsg(fd: i32, msg: *msghdr_const, flags: u32) usize { |
| 786 | 786 | } |
| 787 | 787 | |
| 788 | 788 | pub 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 | 790 | // workaround kernel brokenness: |
| 791 | 791 | // if adding up all iov_len overflows a i32 then split into multiple calls |
| 792 | 792 | // 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 | 32 | options: fmt.FormatOptions, |
| 33 | 33 | context: var, |
| 34 | 34 | comptime Errors: type, |
| 35 | output: fn (@typeOf(context), []const u8) Errors!void, | |
| 35 | output: fn (@TypeOf(context), []const u8) Errors!void, | |
| 36 | 36 | ) Errors!void { |
| 37 | 37 | if (f.len == 0) { |
| 38 | 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 | 214 | |
| 215 | 215 | pub extern "kernel32" stdcallcc fn WaitForSingleObjectEx(hHandle: HANDLE, dwMilliseconds: DWORD, bAlertable: BOOL) DWORD; |
| 216 | 216 | |
| 217 | pub extern "kernel32" stdcallcc fn WaitForMultipleObjects(nCount: DWORD, lpHandle: [*]const HANDLE, bWaitAll:BOOL, dwMilliseconds: DWORD) DWORD; | |
| 217 | pub extern "kernel32" stdcallcc fn WaitForMultipleObjects(nCount: DWORD, lpHandle: [*]const HANDLE, bWaitAll: BOOL, dwMilliseconds: DWORD) DWORD; | |
| 218 | 218 | |
| 219 | 219 | pub extern "kernel32" stdcallcc fn WaitForMultipleObjectsEx( |
| 220 | 220 | nCount: DWORD, |
| 221 | 221 | lpHandle: [*]const HANDLE, |
| 222 | bWaitAll:BOOL, | |
| 222 | bWaitAll: BOOL, | |
| 223 | 223 | dwMilliseconds: DWORD, |
| 224 | 224 | bAlertable: BOOL, |
| 225 | 225 | ) DWORD; |
lib/std/pdb.zig+1-1| ... | ... | @@ -635,7 +635,7 @@ const MsfStream = struct { |
| 635 | 635 | /// Implementation of InStream trait for Pdb.MsfStream |
| 636 | 636 | stream: Stream = undefined, |
| 637 | 637 | |
| 638 | pub const Error = @typeOf(read).ReturnType.ErrorSet; | |
| 638 | pub const Error = @TypeOf(read).ReturnType.ErrorSet; | |
| 639 | 639 | pub const Stream = io.InStream(Error); |
| 640 | 640 | |
| 641 | 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 | 27 | pub fn isSet(self: *ResetEvent) bool { |
| 28 | 28 | return self.os_event.isSet(); |
| 29 | 29 | } |
| 30 | ||
| 30 | ||
| 31 | 31 | /// Sets the event if not already set and |
| 32 | 32 | /// wakes up AT LEAST one thread waiting the event. |
| 33 | 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 | 62 | }; |
| 63 | 63 | |
| 64 | 64 | const DebugEvent = struct { |
| 65 | is_set: @typeOf(set_init), | |
| 65 | is_set: @TypeOf(set_init), | |
| 66 | 66 | |
| 67 | 67 | const set_init = if (std.debug.runtime_safety) false else {}; |
| 68 | 68 | |
| ... | ... | @@ -283,7 +283,7 @@ const PosixEvent = struct { |
| 283 | 283 | |
| 284 | 284 | pub fn init() PosixEvent { |
| 285 | 285 | return PosixEvent{ |
| 286 | .state = .0, | |
| 286 | .state = 0, | |
| 287 | 287 | .cond = c.PTHREAD_COND_INITIALIZER, |
| 288 | 288 | .mutex = c.PTHREAD_MUTEX_INITIALIZER, |
| 289 | 289 | }; |
| ... | ... | @@ -345,8 +345,8 @@ const PosixEvent = struct { |
| 345 | 345 | timeout_abs += @intCast(u64, ts.tv_sec) * time.second; |
| 346 | 346 | timeout_abs += @intCast(u64, ts.tv_nsec); |
| 347 | 347 | } |
| 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)); | |
| 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)); | |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | var dummy_value: u32 = undefined; |
| ... | ... | @@ -426,8 +426,8 @@ test "std.ResetEvent" { |
| 426 | 426 | .event = event, |
| 427 | 427 | .value = 0, |
| 428 | 428 | }; |
| 429 | ||
| 429 | ||
| 430 | 430 | var receiver = try std.Thread.spawn(&context, Context.receiver); |
| 431 | 431 | defer receiver.wait(); |
| 432 | 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 | 122 | self.* = undefined; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | pub fn at(self: var, i: usize) AtType(@typeOf(self)) { | |
| 125 | pub fn at(self: var, i: usize) AtType(@TypeOf(self)) { | |
| 126 | 126 | assert(i < self.len); |
| 127 | 127 | return self.uncheckedAt(i); |
| 128 | 128 | } |
| ... | ... | @@ -213,7 +213,7 @@ pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type |
| 213 | 213 | self.len = new_len; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | pub fn uncheckedAt(self: var, index: usize) AtType(@typeOf(self)) { | |
| 216 | pub fn uncheckedAt(self: var, index: usize) AtType(@TypeOf(self)) { | |
| 217 | 217 | if (index < prealloc_item_count) { |
| 218 | 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 | 125 | } |
| 126 | 126 | |
| 127 | 127 | fn runBuild(builder: *Builder) anyerror!void { |
| 128 | switch (@typeId(@typeOf(root.build).ReturnType)) { | |
| 128 | switch (@typeId(@TypeOf(root.build).ReturnType)) { | |
| 129 | 129 | .Void => root.build(builder), |
| 130 | 130 | .ErrorUnion => try root.build(builder), |
| 131 | 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 | 384 | } { |
| 385 | 385 | @setRuntimeSafety(is_test); |
| 386 | 386 | |
| 387 | var result: @typeOf(__aeabi_uidivmod).ReturnType = undefined; | |
| 387 | var result: @TypeOf(__aeabi_uidivmod).ReturnType = undefined; | |
| 388 | 388 | result.q = __udivmodsi4(n, d, &result.r); |
| 389 | 389 | return result; |
| 390 | 390 | } |
| ... | ... | @@ -395,7 +395,7 @@ extern fn __aeabi_uldivmod(n: u64, d: u64) extern struct { |
| 395 | 395 | } { |
| 396 | 396 | @setRuntimeSafety(is_test); |
| 397 | 397 | |
| 398 | var result: @typeOf(__aeabi_uldivmod).ReturnType = undefined; | |
| 398 | var result: @TypeOf(__aeabi_uldivmod).ReturnType = undefined; | |
| 399 | 399 | result.q = __udivmoddi4(n, d, &result.r); |
| 400 | 400 | return result; |
| 401 | 401 | } |
| ... | ... | @@ -406,7 +406,7 @@ extern fn __aeabi_idivmod(n: i32, d: i32) extern struct { |
| 406 | 406 | } { |
| 407 | 407 | @setRuntimeSafety(is_test); |
| 408 | 408 | |
| 409 | var result: @typeOf(__aeabi_idivmod).ReturnType = undefined; | |
| 409 | var result: @TypeOf(__aeabi_idivmod).ReturnType = undefined; | |
| 410 | 410 | result.q = __divmodsi4(n, d, &result.r); |
| 411 | 411 | return result; |
| 412 | 412 | } |
| ... | ... | @@ -417,7 +417,7 @@ extern fn __aeabi_ldivmod(n: i64, d: i64) extern struct { |
| 417 | 417 | } { |
| 418 | 418 | @setRuntimeSafety(is_test); |
| 419 | 419 | |
| 420 | var result: @typeOf(__aeabi_ldivmod).ReturnType = undefined; | |
| 420 | var result: @TypeOf(__aeabi_ldivmod).ReturnType = undefined; | |
| 421 | 421 | result.q = __divmoddi4(n, d, &result.r); |
| 422 | 422 | return result; |
| 423 | 423 | } |
lib/std/special/start.zig+4-4| ... | ... | @@ -25,7 +25,7 @@ comptime { |
| 25 | 25 | } |
| 26 | 26 | } else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) { |
| 27 | 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 | 29 | @export("main", main, .Weak); |
| 30 | 30 | } |
| 31 | 31 | } else if (builtin.os == .windows) { |
| ... | ... | @@ -69,7 +69,7 @@ extern fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) u |
| 69 | 69 | uefi.handle = handle; |
| 70 | 70 | uefi.system_table = system_table; |
| 71 | 71 | |
| 72 | switch (@typeInfo(@typeOf(root.main).ReturnType)) { | |
| 72 | switch (@typeInfo(@TypeOf(root.main).ReturnType)) { | |
| 73 | 73 | .NoReturn => { |
| 74 | 74 | root.main(); |
| 75 | 75 | }, |
| ... | ... | @@ -248,7 +248,7 @@ async fn callMainAsync(loop: *std.event.Loop) u8 { |
| 248 | 248 | // This is not marked inline because it is called with @asyncCall when |
| 249 | 249 | // there is an event loop. |
| 250 | 250 | fn callMain() u8 { |
| 251 | switch (@typeInfo(@typeOf(root.main).ReturnType)) { | |
| 251 | switch (@typeInfo(@TypeOf(root.main).ReturnType)) { | |
| 252 | 252 | .NoReturn => { |
| 253 | 253 | root.main(); |
| 254 | 254 | }, |
| ... | ... | @@ -270,7 +270,7 @@ fn callMain() u8 { |
| 270 | 270 | } |
| 271 | 271 | return 1; |
| 272 | 272 | }; |
| 273 | switch (@typeInfo(@typeOf(result))) { | |
| 273 | switch (@typeInfo(@TypeOf(result))) { | |
| 274 | 274 | .Void => return 0, |
| 275 | 275 | .Int => |info| { |
| 276 | 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 | 21 | /// equal, prints diagnostics to stderr to show exactly how they are not equal, |
| 22 | 22 | /// then aborts. |
| 23 | 23 | /// The types must match exactly. |
| 24 | pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { | |
| 25 | switch (@typeInfo(@typeOf(actual))) { | |
| 24 | pub fn expectEqual(expected: var, actual: @TypeOf(expected)) void { | |
| 25 | switch (@typeInfo(@TypeOf(actual))) { | |
| 26 | 26 | .NoReturn, |
| 27 | 27 | .BoundFn, |
| 28 | 28 | .Opaque, |
| 29 | 29 | .Frame, |
| 30 | 30 | .AnyFrame, |
| 31 | => @compileError("value of type " ++ @typeName(@typeOf(actual)) ++ " encountered"), | |
| 31 | => @compileError("value of type " ++ @typeName(@TypeOf(actual)) ++ " encountered"), | |
| 32 | 32 | |
| 33 | 33 | .Undefined, |
| 34 | 34 | .Null, |
| ... | ... | @@ -87,7 +87,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { |
| 87 | 87 | @compileError("Unable to compare untagged union values"); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | const TagType = @TagType(@typeOf(expected)); | |
| 90 | const TagType = @TagType(@TypeOf(expected)); | |
| 91 | 91 | |
| 92 | 92 | const expectedTag = @as(TagType, expected); |
| 93 | 93 | const actualTag = @as(TagType, actual); |
| ... | ... | @@ -95,7 +95,7 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { |
| 95 | 95 | expectEqual(expectedTag, actualTag); |
| 96 | 96 | |
| 97 | 97 | // 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 | 99 | if (std.mem.eql(u8, fld.name, @tagName(actualTag))) { |
| 100 | 100 | expectEqual(@field(expected, fld.name), @field(actual, fld.name)); |
| 101 | 101 | return; |
lib/std/thread.zig+5-5| ... | ... | @@ -138,7 +138,7 @@ pub const Thread = struct { |
| 138 | 138 | }; |
| 139 | 139 | |
| 140 | 140 | /// caller must call wait on the returned thread |
| 141 | /// fn startFn(@typeOf(context)) T | |
| 141 | /// fn startFn(@TypeOf(context)) T | |
| 142 | 142 | /// where T is u8, noreturn, void, or !void |
| 143 | 143 | /// caller must call wait on the returned thread |
| 144 | 144 | pub fn spawn(context: var, comptime startFn: var) SpawnError!*Thread { |
| ... | ... | @@ -147,8 +147,8 @@ pub const Thread = struct { |
| 147 | 147 | // https://github.com/ziglang/zig/issues/157 |
| 148 | 148 | const default_stack_size = 16 * 1024 * 1024; |
| 149 | 149 | |
| 150 | const Context = @typeOf(context); | |
| 151 | comptime assert(@ArgType(@typeOf(startFn), 0) == Context); | |
| 150 | const Context = @TypeOf(context); | |
| 151 | comptime assert(@ArgType(@TypeOf(startFn), 0) == Context); | |
| 152 | 152 | |
| 153 | 153 | if (builtin.os == builtin.Os.windows) { |
| 154 | 154 | const WinThread = struct { |
| ... | ... | @@ -158,7 +158,7 @@ pub const Thread = struct { |
| 158 | 158 | }; |
| 159 | 159 | extern fn threadMain(raw_arg: windows.LPVOID) windows.DWORD { |
| 160 | 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 | 162 | .Int => { |
| 163 | 163 | return startFn(arg); |
| 164 | 164 | }, |
| ... | ... | @@ -201,7 +201,7 @@ pub const Thread = struct { |
| 201 | 201 | extern fn linuxThreadMain(ctx_addr: usize) u8 { |
| 202 | 202 | const arg = if (@sizeOf(Context) == 0) {} else @intToPtr(*const Context, ctx_addr).*; |
| 203 | 203 | |
| 204 | switch (@typeId(@typeOf(startFn).ReturnType)) { | |
| 204 | switch (@typeId(@TypeOf(startFn).ReturnType)) { | |
| 205 | 205 | .Int => { |
| 206 | 206 | return startFn(arg); |
| 207 | 207 | }, |
lib/std/zig/parser_test.zig+13-2| ... | ... | @@ -1,3 +1,14 @@ |
| 1 | // TODO: Remove condition after deprecating 'typeOf'. See https://github.com/ziglang/zig/issues/1348 | |
| 2 | test "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 | ||
| 1 | 12 | test "zig fmt: comptime struct field" { |
| 2 | 13 | try testCanonical( |
| 3 | 14 | \\const Foo = struct { |
| ... | ... | @@ -1060,7 +1071,7 @@ test "zig fmt: line comment after doc comment" { |
| 1060 | 1071 | test "zig fmt: float literal with exponent" { |
| 1061 | 1072 | try testCanonical( |
| 1062 | 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 | 2604 | try testTransform( |
| 2594 | 2605 | \\var bar = Bar{ |
| 2595 | 2606 | \\ .x = 10, // test |
| 2596 | \\ .y = "test" | |
| 2607 | \\ .y = "test" | |
| 2597 | 2608 | \\ // test |
| 2598 | 2609 | \\}; |
| 2599 | 2610 | \\ |
lib/std/zig/render.zig+22-16| ... | ... | @@ -13,19 +13,19 @@ pub const Error = error{ |
| 13 | 13 | }; |
| 14 | 14 | |
| 15 | 15 | /// Returns whether anything changed |
| 16 | pub 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); | |
| 16 | pub 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); | |
| 18 | 18 | |
| 19 | 19 | var anything_changed: bool = false; |
| 20 | 20 | |
| 21 | 21 | // make a passthrough stream that checks whether something changed |
| 22 | 22 | const MyStream = struct { |
| 23 | 23 | const MyStream = @This(); |
| 24 | const StreamError = @typeOf(stream).Child.Error; | |
| 24 | const StreamError = @TypeOf(stream).Child.Error; | |
| 25 | 25 | const Stream = std.io.OutStream(StreamError); |
| 26 | 26 | |
| 27 | 27 | anything_changed_ptr: *bool, |
| 28 | child_stream: @typeOf(stream), | |
| 28 | child_stream: @TypeOf(stream), | |
| 29 | 29 | stream: Stream, |
| 30 | 30 | source_index: usize, |
| 31 | 31 | source: []const u8, |
| ... | ... | @@ -70,7 +70,7 @@ fn renderRoot( |
| 70 | 70 | allocator: *mem.Allocator, |
| 71 | 71 | stream: var, |
| 72 | 72 | tree: *ast.Tree, |
| 73 | ) (@typeOf(stream).Child.Error || Error)!void { | |
| 73 | ) (@TypeOf(stream).Child.Error || Error)!void { | |
| 74 | 74 | var tok_it = tree.tokens.iterator(0); |
| 75 | 75 | |
| 76 | 76 | // render all the line comments at the beginning of the file |
| ... | ... | @@ -190,7 +190,7 @@ fn renderRoot( |
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | fn renderExtraNewline(tree: *ast.Tree, stream: var, start_col: *usize, node: *ast.Node) @typeOf(stream).Child.Error!void { | |
| 193 | fn renderExtraNewline(tree: *ast.Tree, stream: var, start_col: *usize, node: *ast.Node) @TypeOf(stream).Child.Error!void { | |
| 194 | 194 | const first_token = node.firstToken(); |
| 195 | 195 | var prev_token = first_token; |
| 196 | 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 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, indent: usize, start_col: *usize, decl: *ast.Node) (@typeOf(stream).Child.Error || Error)!void { | |
| 207 | fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, indent: usize, start_col: *usize, decl: *ast.Node) (@TypeOf(stream).Child.Error || Error)!void { | |
| 208 | 208 | switch (decl.id) { |
| 209 | 209 | .FnProto => { |
| 210 | 210 | const fn_proto = @fieldParentPtr(ast.Node.FnProto, "base", decl); |
| ... | ... | @@ -325,7 +325,7 @@ fn renderExpression( |
| 325 | 325 | start_col: *usize, |
| 326 | 326 | base: *ast.Node, |
| 327 | 327 | space: Space, |
| 328 | ) (@typeOf(stream).Child.Error || Error)!void { | |
| 328 | ) (@TypeOf(stream).Child.Error || Error)!void { | |
| 329 | 329 | switch (base.id) { |
| 330 | 330 | .Identifier => { |
| 331 | 331 | const identifier = @fieldParentPtr(ast.Node.Identifier, "base", base); |
| ... | ... | @@ -1249,7 +1249,13 @@ fn renderExpression( |
| 1249 | 1249 | .BuiltinCall => { |
| 1250 | 1250 | const builtin_call = @fieldParentPtr(ast.Node.BuiltinCall, "base", base); |
| 1251 | 1251 | |
| 1252 | try renderToken(tree, stream, builtin_call.builtin_token, indent, start_col, Space.None); // @name | |
| 1252 | // 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 | 1259 | try renderToken(tree, stream, tree.nextToken(builtin_call.builtin_token), indent, start_col, Space.None); // ( |
| 1254 | 1260 | |
| 1255 | 1261 | var it = builtin_call.params.iterator(0); |
| ... | ... | @@ -1897,7 +1903,7 @@ fn renderVarDecl( |
| 1897 | 1903 | indent: usize, |
| 1898 | 1904 | start_col: *usize, |
| 1899 | 1905 | var_decl: *ast.Node.VarDecl, |
| 1900 | ) (@typeOf(stream).Child.Error || Error)!void { | |
| 1906 | ) (@TypeOf(stream).Child.Error || Error)!void { | |
| 1901 | 1907 | if (var_decl.visib_token) |visib_token| { |
| 1902 | 1908 | try renderToken(tree, stream, visib_token, indent, start_col, Space.Space); // pub |
| 1903 | 1909 | } |
| ... | ... | @@ -1970,7 +1976,7 @@ fn renderParamDecl( |
| 1970 | 1976 | start_col: *usize, |
| 1971 | 1977 | base: *ast.Node, |
| 1972 | 1978 | space: Space, |
| 1973 | ) (@typeOf(stream).Child.Error || Error)!void { | |
| 1979 | ) (@TypeOf(stream).Child.Error || Error)!void { | |
| 1974 | 1980 | const param_decl = @fieldParentPtr(ast.Node.ParamDecl, "base", base); |
| 1975 | 1981 | |
| 1976 | 1982 | try renderDocComments(tree, stream, param_decl, indent, start_col); |
| ... | ... | @@ -1999,7 +2005,7 @@ fn renderStatement( |
| 1999 | 2005 | indent: usize, |
| 2000 | 2006 | start_col: *usize, |
| 2001 | 2007 | base: *ast.Node, |
| 2002 | ) (@typeOf(stream).Child.Error || Error)!void { | |
| 2008 | ) (@TypeOf(stream).Child.Error || Error)!void { | |
| 2003 | 2009 | switch (base.id) { |
| 2004 | 2010 | .VarDecl => { |
| 2005 | 2011 | const var_decl = @fieldParentPtr(ast.Node.VarDecl, "base", base); |
| ... | ... | @@ -2038,7 +2044,7 @@ fn renderTokenOffset( |
| 2038 | 2044 | start_col: *usize, |
| 2039 | 2045 | space: Space, |
| 2040 | 2046 | token_skip_bytes: usize, |
| 2041 | ) (@typeOf(stream).Child.Error || Error)!void { | |
| 2047 | ) (@TypeOf(stream).Child.Error || Error)!void { | |
| 2042 | 2048 | if (space == Space.BlockStart) { |
| 2043 | 2049 | if (start_col.* < indent + indent_delta) |
| 2044 | 2050 | return renderToken(tree, stream, token_index, indent, start_col, Space.Space); |
| ... | ... | @@ -2226,7 +2232,7 @@ fn renderToken( |
| 2226 | 2232 | indent: usize, |
| 2227 | 2233 | start_col: *usize, |
| 2228 | 2234 | space: Space, |
| 2229 | ) (@typeOf(stream).Child.Error || Error)!void { | |
| 2235 | ) (@TypeOf(stream).Child.Error || Error)!void { | |
| 2230 | 2236 | return renderTokenOffset(tree, stream, token_index, indent, start_col, space, 0); |
| 2231 | 2237 | } |
| 2232 | 2238 | |
| ... | ... | @@ -2236,7 +2242,7 @@ fn renderDocComments( |
| 2236 | 2242 | node: var, |
| 2237 | 2243 | indent: usize, |
| 2238 | 2244 | start_col: *usize, |
| 2239 | ) (@typeOf(stream).Child.Error || Error)!void { | |
| 2245 | ) (@TypeOf(stream).Child.Error || Error)!void { | |
| 2240 | 2246 | const comment = node.doc_comments orelse return; |
| 2241 | 2247 | var it = comment.lines.iterator(0); |
| 2242 | 2248 | const first_token = node.firstToken(); |
| ... | ... | @@ -2302,7 +2308,7 @@ const FindByteOutStream = struct { |
| 2302 | 2308 | } |
| 2303 | 2309 | }; |
| 2304 | 2310 | |
| 2305 | fn copyFixingWhitespace(stream: var, slice: []const u8) @typeOf(stream).Child.Error!void { | |
| 2311 | fn copyFixingWhitespace(stream: var, slice: []const u8) @TypeOf(stream).Child.Error!void { | |
| 2306 | 2312 | for (slice) |byte| switch (byte) { |
| 2307 | 2313 | '\t' => try stream.write(" "), |
| 2308 | 2314 | '\r' => {}, |
src-self-hosted/dep_tokenizer.zig+2-2| ... | ... | @@ -1021,8 +1021,8 @@ comptime { |
| 1021 | 1021 | // output: must be a function that takes a `self` idiom parameter |
| 1022 | 1022 | // and a bytes parameter |
| 1023 | 1023 | // context: must be that self |
| 1024 | fn makeOutput(output: var, context: var) Output(@typeOf(output)) { | |
| 1025 | return Output(@typeOf(output)){ | |
| 1024 | fn makeOutput(output: var, context: var) Output(@TypeOf(output)) { | |
| 1025 | return Output(@TypeOf(output)){ | |
| 1026 | 1026 | .output = output, |
| 1027 | 1027 | .context = context, |
| 1028 | 1028 | }; |
src-self-hosted/ir.zig+1-1| ... | ... | @@ -1807,7 +1807,7 @@ pub const Builder = struct { |
| 1807 | 1807 | // Look at the params and ref() other instructions |
| 1808 | 1808 | comptime var i = 0; |
| 1809 | 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 | 1811 | switch (FieldType) { |
| 1812 | 1812 | *Inst => @field(inst.params, @memberName(I.Params, i)).ref(self), |
| 1813 | 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 | 72 | inline for (keys) |key, i| { |
| 73 | 73 | if (std.mem.eql(u8, name, key)) { |
| 74 | 74 | found_keys[i].found = true; |
| 75 | switch (@typeInfo(@typeOf(@field(self, key)))) { | |
| 75 | switch (@typeInfo(@TypeOf(@field(self, key)))) { | |
| 76 | 76 | .Optional => { |
| 77 | 77 | if (value.len == 0) { |
| 78 | 78 | @field(self, key) = null; |
src-self-hosted/stage1.zig+4-6| ... | ... | @@ -270,11 +270,9 @@ const FmtError = error{ |
| 270 | 270 | FileBusy, |
| 271 | 271 | } || fs.File.OpenError; |
| 272 | 272 | |
| 273 | fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtError!void { | |
| 274 | const file_path = try std.mem.dupe(fmt.allocator, u8, file_path_ref); | |
| 275 | defer fmt.allocator.free(file_path); | |
| 276 | ||
| 277 | if (try fmt.seen.put(file_path, {})) |_| return; | |
| 273 | fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void { | |
| 274 | if (fmt.seen.exists(file_path)) return; | |
| 275 | try fmt.seen.put(file_path); | |
| 278 | 276 | |
| 279 | 277 | const source_code = io.readFileAlloc(fmt.allocator, file_path) catch |err| switch (err) { |
| 280 | 278 | error.IsDir, error.AccessDenied => { |
| ... | ... | @@ -341,7 +339,7 @@ const Fmt = struct { |
| 341 | 339 | color: errmsg.Color, |
| 342 | 340 | allocator: *mem.Allocator, |
| 343 | 341 | |
| 344 | const SeenMap = std.StringHashMap(void); | |
| 342 | const SeenMap = std.BufSet; | |
| 345 | 343 | }; |
| 346 | 344 | |
| 347 | 345 | fn printErrMsgToFile( |
src-self-hosted/translate_c.zig+2-2| ... | ... | @@ -1147,7 +1147,7 @@ fn transCreateNodeAPInt(c: *Context, int: ?*const ZigClangAPSInt) !*ast.Node { |
| 1147 | 1147 | var big = try std.math.big.Int.initCapacity(c.a(), num_limbs); |
| 1148 | 1148 | defer big.deinit(); |
| 1149 | 1149 | const data = ZigClangAPSInt_getRawData(int.?); |
| 1150 | var i: @typeOf(num_limbs) = 0; | |
| 1150 | var i: @TypeOf(num_limbs) = 0; | |
| 1151 | 1151 | while (i < num_limbs) : (i += 1) big.limbs[i] = data[i]; |
| 1152 | 1152 | const str = big.toString(c.a(), 10) catch |err| switch (err) { |
| 1153 | 1153 | error.OutOfMemory => return error.OutOfMemory, |
| ... | ... | @@ -1416,7 +1416,7 @@ fn revertAndWarn( |
| 1416 | 1416 | source_loc: ZigClangSourceLocation, |
| 1417 | 1417 | comptime format: []const u8, |
| 1418 | 1418 | args: var, |
| 1419 | ) (@typeOf(err) || error{OutOfMemory}) { | |
| 1419 | ) (@TypeOf(err) || error{OutOfMemory}) { | |
| 1420 | 1420 | rp.activate(); |
| 1421 | 1421 | try emitWarning(rp.c, source_loc, format, args); |
| 1422 | 1422 | return err; |
src-self-hosted/type.zig+3-3| ... | ... | @@ -1038,14 +1038,14 @@ pub const Type = struct { |
| 1038 | 1038 | }; |
| 1039 | 1039 | |
| 1040 | 1040 | fn hashAny(x: var, comptime seed: u64) u32 { |
| 1041 | switch (@typeInfo(@typeOf(x))) { | |
| 1041 | switch (@typeInfo(@TypeOf(x))) { | |
| 1042 | 1042 | .Int => |info| { |
| 1043 | 1043 | comptime var rng = comptime std.rand.DefaultPrng.init(seed); |
| 1044 | 1044 | const unsigned_x = @bitCast(@IntType(false, info.bits), x); |
| 1045 | 1045 | if (info.bits <= 32) { |
| 1046 | 1046 | return @as(u32, unsigned_x) *% comptime rng.random.scalar(u32); |
| 1047 | 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 | 1051 | .Pointer => |info| { |
| ... | ... | @@ -1069,6 +1069,6 @@ fn hashAny(x: var, comptime seed: u64) u32 { |
| 1069 | 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 | 2393 | ZigFn *fn_entry; |
| 2394 | 2394 | }; |
| 2395 | 2395 | |
| 2396 | // This scope is created for a @typeOf. | |
| 2396 | // This scope is created for a @TypeOf. | |
| 2397 | 2397 | // All runtime side-effects are elided within it. |
| 2398 | 2398 | // NodeTypeFnCallExpr |
| 2399 | 2399 | struct ScopeTypeOf { |
src/analyze.cpp+2-2| ... | ... | @@ -121,7 +121,7 @@ static ScopeExpr *find_expr_scope(Scope *scope) { |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | static 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 | 125 | g->resolve_queue_index + g->fn_defs_index, |
| 126 | 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 | 1732 | ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry) { |
| 1733 | 1733 | ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); |
| 1734 | 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 | 1736 | err_set_type->data.error_set.err_count = 0; |
| 1737 | 1737 | err_set_type->data.error_set.errors = nullptr; |
| 1738 | 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 | 1647 | ptr_type->data.pointer.vector_index, false); |
| 1648 | 1648 | LLVMValueRef loaded_vector = gen_load(g, ptr, ptr_type, ""); |
| 1649 | 1649 | LLVMValueRef new_vector = LLVMBuildInsertElement(g->builder, loaded_vector, value, |
| 1650 | index_val, ""); | |
| 1650 | index_val, ""); | |
| 1651 | 1651 | gen_store(g, new_vector, ptr, ptr_type); |
| 1652 | 1652 | return; |
| 1653 | 1653 | } |
| ... | ... | @@ -8067,7 +8067,7 @@ static void define_builtin_fns(CodeGen *g) { |
| 8067 | 8067 | create_builtin_fn(g, BuiltinFnIdTypeInfo, "typeInfo", 1); |
| 8068 | 8068 | create_builtin_fn(g, BuiltinFnIdType, "Type", 1); |
| 8069 | 8069 | create_builtin_fn(g, BuiltinFnIdHasField, "hasField", 2); |
| 8070 | create_builtin_fn(g, BuiltinFnIdTypeof, "typeOf", 1); // TODO rename to TypeOf | |
| 8070 | create_builtin_fn(g, BuiltinFnIdTypeof, "TypeOf", 1); | |
| 8071 | 8071 | create_builtin_fn(g, BuiltinFnIdAddWithOverflow, "addWithOverflow", 4); |
| 8072 | 8072 | create_builtin_fn(g, BuiltinFnIdSubWithOverflow, "subWithOverflow", 4); |
| 8073 | 8073 | create_builtin_fn(g, BuiltinFnIdMulWithOverflow, "mulWithOverflow", 4); |
| ... | ... | @@ -8407,7 +8407,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) { |
| 8407 | 8407 | break; |
| 8408 | 8408 | } |
| 8409 | 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 | 8411 | buf_appendf(contents, "pub const link_mode = LinkMode.%s;\n", link_type); |
| 8412 | 8412 | buf_appendf(contents, "pub const is_test = %s;\n", bool_to_str(g->is_test_build)); |
| 8413 | 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 | 9267 | } |
| 9268 | 9268 | } |
| 9269 | 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 | 9271 | continue; |
| 9272 | 9272 | } |
| 9273 | 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 | 10413 | return result; |
| 10414 | 10414 | } |
| 10415 | 10415 | |
| 10416 | bool ok_cv_qualifiers = | |
| 10416 | bool ok_cv_qualifiers = | |
| 10417 | 10417 | (!actual_ptr_type->data.pointer.is_const || wanted_ptr_type->data.pointer.is_const) && |
| 10418 | 10418 | (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile); |
| 10419 | 10419 | if (!ok_cv_qualifiers) { |
| ... | ... | @@ -13779,7 +13779,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13779 | 13779 | (wanted_type->id == ZigTypeIdOptional && wanted_type->data.maybe.child_type->id == ZigTypeIdEnum)) |
| 13780 | 13780 | { |
| 13781 | 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 | 13783 | return result; |
| 13784 | 13784 | |
| 13785 | 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 | 13790 | (wanted_type->id == ZigTypeIdErrorUnion && wanted_type->data.error_union.payload_type->id == ZigTypeIdEnum)) |
| 13791 | 13791 | { |
| 13792 | 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 | 13794 | return result; |
| 13795 | ||
| 13795 | ||
| 13796 | 13796 | return ir_analyze_err_wrap_payload(ira, result, value, wanted_type, nullptr); |
| 13797 | 13797 | } |
| 13798 | 13798 | |
| ... | ... | @@ -19328,7 +19328,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 19328 | 19328 | { |
| 19329 | 19329 | size_t offset = ptr_field->data.x_ptr.data.base_array.elem_index; |
| 19330 | 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 | 19332 | ConstArraySpecialBuf) |
| 19333 | 19333 | { |
| 19334 | 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 | 873 | } |
| 874 | 874 | |
| 875 | 875 | static void ir_print_typeof(IrPrint *irp, IrInstructionTypeOf *instruction) { |
| 876 | fprintf(irp->f, "@typeOf("); | |
| 876 | fprintf(irp->f, "@TypeOf("); | |
| 877 | 877 | ir_print_other_instruction(irp, instruction->value); |
| 878 | 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 | 4230 | emit_warning(c, ZigClangTypedefNameDecl_getLocation(typedef_decl), |
| 4231 | 4231 | "typedef %s - unresolved child type", buf_ptr(type_name)); |
| 4232 | 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 | 4234 | return nullptr; |
| 4235 | 4235 | } |
| 4236 | 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 | 4919 | *tok_i += 1; |
| 4920 | 4920 | |
| 4921 | 4921 | |
| 4922 | //if (@typeId(@typeOf(x)) == @import("builtin").TypeId.Pointer) | |
| 4922 | //if (@typeId(@TypeOf(x)) == @import("builtin").TypeId.Pointer) | |
| 4923 | 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 | 4925 | // @intToPtr(dest, x) |
| 4926 | 4926 | //else |
| 4927 | 4927 | // (dest)(x) |
| ... | ... | @@ -4931,7 +4931,7 @@ static AstNode *parse_ctok_primary_expr(Context *c, CTokenize *ctok, size_t *tok |
| 4931 | 4931 | AstNode *typeid_type = trans_create_node_field_access_str(c, import_builtin, "TypeId"); |
| 4932 | 4932 | AstNode *typeid_pointer = trans_create_node_field_access_str(c, typeid_type, "Pointer"); |
| 4933 | 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 | 4935 | typeof_x->data.fn_call_expr.params.append(node_to_cast); |
| 4936 | 4936 | AstNode *typeid_value = trans_create_node_builtin_fn_call_str(c, "typeId"); |
| 4937 | 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 | 258 | cases.add("order-independent declarations", |
| 259 | 259 | \\const io = @import("std").io; |
| 260 | 260 | \\const z = io.stdin_fileno; |
| 261 | \\const x : @typeOf(y) = 1234; | |
| 261 | \\const x : @TypeOf(y) = 1234; | |
| 262 | 262 | \\const y : u16 = 5678; |
| 263 | 263 | \\pub fn main() void { |
| 264 | 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 | 267 | \\ const stdout = &io.getStdOut().outStream().stream; |
| 268 | 268 | \\ stdout.print("OK\n", .{}) catch unreachable; |
| 269 | 269 | \\ return 0; |
test/compile_errors.zig+65-65| ... | ... | @@ -154,7 +154,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 154 | 154 | \\ }; |
| 155 | 155 | \\} |
| 156 | 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 | }); |
| 159 | 159 | |
| 160 | 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 | 854 | cases.add("field access of slices", |
| 855 | 855 | \\export fn entry() void { |
| 856 | 856 | \\ var slice: []i32 = undefined; |
| 857 | \\ const info = @typeOf(slice).unknown; | |
| 857 | \\ const info = @TypeOf(slice).unknown; | |
| 858 | 858 | \\} |
| 859 | 859 | , &[_][]const u8{ |
| 860 | 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 | 894 | |
| 895 | 895 | cases.add("@sizeOf bad type", |
| 896 | 896 | \\export fn entry() usize { |
| 897 | \\ return @sizeOf(@typeOf(null)); | |
| 897 | \\ return @sizeOf(@TypeOf(null)); | |
| 898 | 898 | \\} |
| 899 | 899 | , &[_][]const u8{ |
| 900 | 900 | "tmp.zig:2:20: error: no size available for type '(null)'", |
| ... | ... | @@ -1033,7 +1033,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1033 | 1033 | |
| 1034 | 1034 | cases.add("bogus compile var", |
| 1035 | 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 | 1037 | , &[_][]const u8{ |
| 1038 | 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 | 1080 | \\var foo: Foo = undefined; |
| 1081 | 1081 | \\ |
| 1082 | 1082 | \\export fn entry() usize { |
| 1083 | \\ return @sizeOf(@typeOf(foo.x)); | |
| 1083 | \\ return @sizeOf(@TypeOf(foo.x)); | |
| 1084 | 1084 | \\} |
| 1085 | 1085 | , &[_][]const u8{ |
| 1086 | 1086 | "tmp.zig:1:13: error: struct 'Foo' depends on itself", |
| ... | ... | @@ -1118,8 +1118,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1118 | 1118 | }); |
| 1119 | 1119 | |
| 1120 | 1120 | cases.add("top level decl dependency loop", |
| 1121 | \\const a : @typeOf(b) = 0; | |
| 1122 | \\const b : @typeOf(a) = 0; | |
| 1121 | \\const a : @TypeOf(b) = 0; | |
| 1122 | \\const b : @TypeOf(a) = 0; | |
| 1123 | 1123 | \\export fn entry() void { |
| 1124 | 1124 | \\ const c = a + b; |
| 1125 | 1125 | \\} |
| ... | ... | @@ -1620,7 +1620,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 1620 | 1620 | \\var x: f64 = 1.0; |
| 1621 | 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 | 1624 | , &[_][]const u8{ |
| 1625 | 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 | 2494 | \\ } |
| 2495 | 2495 | \\} |
| 2496 | 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 | 2498 | "tmp.zig:3:14: note: other value is here", |
| 2499 | 2499 | }); |
| 2500 | 2500 | |
| ... | ... | @@ -2626,7 +2626,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 2626 | 2626 | \\ try foo(); |
| 2627 | 2627 | \\} |
| 2628 | 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 | }); |
| 2631 | 2631 | |
| 2632 | 2632 | cases.add("implicit cast of error set not a subset", |
| ... | ... | @@ -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 | 3559 | , &[_][]const u8{ |
| 3560 | 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 | 3577 | \\ } |
| 3578 | 3578 | \\} |
| 3579 | 3579 | \\ |
| 3580 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } | |
| 3580 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } | |
| 3581 | 3581 | , &[_][]const u8{ |
| 3582 | 3582 | "tmp.zig:13:15: error: duplicate switch value", |
| 3583 | 3583 | "tmp.zig:10:15: note: other value is here", |
| ... | ... | @@ -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 | 3605 | , &[_][]const u8{ |
| 3606 | 3606 | "tmp.zig:13:15: error: duplicate switch value", |
| 3607 | 3607 | "tmp.zig:10:15: note: other value is here", |
| ... | ... | @@ -3628,7 +3628,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3628 | 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 | 3632 | , &[_][]const u8{ |
| 3633 | 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 | 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 | 3646 | , &[_][]const u8{ |
| 3647 | 3647 | "tmp.zig:6:9: error: duplicate switch value", |
| 3648 | 3648 | "tmp.zig:5:14: note: previous value is here", |
| ... | ... | @@ -3655,7 +3655,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3655 | 3655 | \\ } |
| 3656 | 3656 | \\} |
| 3657 | 3657 | \\const y: u8 = 100; |
| 3658 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } | |
| 3658 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } | |
| 3659 | 3659 | , &[_][]const u8{ |
| 3660 | 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 | 3673 | \\const derp: usize = 1234; |
| 3674 | 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 | 3677 | , &[_][]const u8{ |
| 3678 | 3678 | "tmp.zig:3:11: error: expected array, found 'usize'", |
| 3679 | 3679 | }); |
| ... | ... | @@ -3683,14 +3683,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3683 | 3683 | \\ return s ++ "foo"; |
| 3684 | 3684 | \\} |
| 3685 | 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 | 3687 | , &[_][]const u8{ |
| 3688 | 3688 | "tmp.zig:2:12: error: unable to evaluate constant expression", |
| 3689 | 3689 | }); |
| 3690 | 3690 | |
| 3691 | 3691 | cases.add("@cImport with bogus include", |
| 3692 | 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 | 3694 | , &[_][]const u8{ |
| 3695 | 3695 | "tmp.zig:1:11: error: C import failed", |
| 3696 | 3696 | ".h:1:10: note: 'bogus.h' file not found", |
| ... | ... | @@ -3700,14 +3700,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3700 | 3700 | \\const x = 3; |
| 3701 | 3701 | \\const y = &x; |
| 3702 | 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 | 3704 | , &[_][]const u8{ |
| 3705 | 3705 | "tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'", |
| 3706 | 3706 | }); |
| 3707 | 3707 | |
| 3708 | 3708 | cases.add("integer overflow error", |
| 3709 | 3709 | \\const x : u8 = 300; |
| 3710 | \\export fn entry() usize { return @sizeOf(@typeOf(x)); } | |
| 3710 | \\export fn entry() usize { return @sizeOf(@TypeOf(x)); } | |
| 3711 | 3711 | , &[_][]const u8{ |
| 3712 | 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 | 3736 | \\ } |
| 3737 | 3737 | \\}; |
| 3738 | 3738 | \\ |
| 3739 | \\const member_fn_type = @typeOf(Foo.member_a); | |
| 3739 | \\const member_fn_type = @TypeOf(Foo.member_a); | |
| 3740 | 3740 | \\const members = [_]member_fn_type { |
| 3741 | 3741 | \\ Foo.member_a, |
| 3742 | 3742 | \\ Foo.member_b, |
| ... | ... | @@ -3746,21 +3746,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3746 | 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 | 3750 | , &[_][]const u8{ |
| 3751 | 3751 | "tmp.zig:20:34: error: expected 1 arguments, found 0", |
| 3752 | 3752 | }); |
| 3753 | 3753 | |
| 3754 | 3754 | cases.add("missing function name", |
| 3755 | 3755 | \\fn () void {} |
| 3756 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } | |
| 3756 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } | |
| 3757 | 3757 | , &[_][]const u8{ |
| 3758 | 3758 | "tmp.zig:1:1: error: missing function name", |
| 3759 | 3759 | }); |
| 3760 | 3760 | |
| 3761 | 3761 | cases.add("missing param name", |
| 3762 | 3762 | \\fn f(i32) void {} |
| 3763 | \\export fn entry() usize { return @sizeOf(@typeOf(f)); } | |
| 3763 | \\export fn entry() usize { return @sizeOf(@TypeOf(f)); } | |
| 3764 | 3764 | , &[_][]const u8{ |
| 3765 | 3765 | "tmp.zig:1:6: error: missing parameter name", |
| 3766 | 3766 | }); |
| ... | ... | @@ -3770,7 +3770,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3770 | 3770 | \\fn a() i32 {return 0;} |
| 3771 | 3771 | \\fn b() i32 {return 1;} |
| 3772 | 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 | 3774 | , &[_][]const u8{ |
| 3775 | 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 | 3781 | \\pub fn b(x: i32) i32 {return x + 1;} |
| 3782 | 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 | 3785 | , &[_][]const u8{ |
| 3786 | 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 | 3789 | cases.add("colliding invalid top level functions", |
| 3790 | 3790 | \\fn func() bogus {} |
| 3791 | 3791 | \\fn func() bogus {} |
| 3792 | \\export fn entry() usize { return @sizeOf(@typeOf(func)); } | |
| 3792 | \\export fn entry() usize { return @sizeOf(@TypeOf(func)); } | |
| 3793 | 3793 | , &[_][]const u8{ |
| 3794 | 3794 | "tmp.zig:2:1: error: redefinition of 'func'", |
| 3795 | 3795 | }); |
| ... | ... | @@ -3801,7 +3801,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3801 | 3801 | \\var global_var: usize = 1; |
| 3802 | 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 | 3805 | , &[_][]const u8{ |
| 3806 | 3806 | "tmp.zig:5:25: error: unable to evaluate constant expression", |
| 3807 | 3807 | "tmp.zig:2:12: note: referenced here", |
| ... | ... | @@ -3813,7 +3813,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3813 | 3813 | \\}; |
| 3814 | 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 | 3817 | , &[_][]const u8{ |
| 3818 | 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 | 3824 | \\const int_x = @as(u32, 1) / @as(u32, 0); |
| 3825 | 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)); } | |
| 3828 | \\export fn entry2() usize { return @sizeOf(@typeOf(lit_float_x)); } | |
| 3829 | \\export fn entry3() usize { return @sizeOf(@typeOf(int_x)); } | |
| 3830 | \\export fn entry4() usize { return @sizeOf(@typeOf(float_x)); } | |
| 3827 | \\export fn entry1() usize { return @sizeOf(@TypeOf(lit_int_x)); } | |
| 3828 | \\export fn entry2() usize { return @sizeOf(@TypeOf(lit_float_x)); } | |
| 3829 | \\export fn entry3() usize { return @sizeOf(@TypeOf(int_x)); } | |
| 3830 | \\export fn entry4() usize { return @sizeOf(@TypeOf(float_x)); } | |
| 3831 | 3831 | , &[_][]const u8{ |
| 3832 | 3832 | "tmp.zig:1:21: error: division by zero", |
| 3833 | 3833 | "tmp.zig:2:25: error: division by zero", |
| ... | ... | @@ -3839,7 +3839,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3839 | 3839 | \\const foo = "a |
| 3840 | 3840 | \\b"; |
| 3841 | 3841 | \\ |
| 3842 | \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } | |
| 3842 | \\export fn entry() usize { return @sizeOf(@TypeOf(foo)); } | |
| 3843 | 3843 | , &[_][]const u8{ |
| 3844 | 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 | 3848 | \\fn foo() void {} |
| 3849 | 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 | 3852 | , &[_][]const u8{ |
| 3853 | 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 | 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 | 3863 | , &[_][]const u8{ |
| 3864 | 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 | 3867 | cases.add("assign null to non-optional pointer", |
| 3868 | 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 | 3871 | , &[_][]const u8{ |
| 3872 | 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 | 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 | 3891 | , &[_][]const u8{ |
| 3892 | 3892 | "tmp.zig:3:14: error: division by zero", |
| 3893 | 3893 | "tmp.zig:1:14: note: referenced here", |
| ... | ... | @@ -3896,7 +3896,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 3896 | 3896 | cases.add("branch on undefined value", |
| 3897 | 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 | 3900 | , &[_][]const u8{ |
| 3901 | 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 | 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 | 4280 | , &[_][]const u8{ |
| 4281 | 4281 | "tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches", |
| 4282 | 4282 | "tmp.zig:1:37: note: referenced here", |
| ... | ... | @@ -4286,7 +4286,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4286 | 4286 | cases.add("@embedFile with bogus file", |
| 4287 | 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 | 4290 | , &[_][]const u8{ |
| 4291 | 4291 | "tmp.zig:1:29: error: unable to find '", |
| 4292 | 4292 | "bogus.txt'", |
| ... | ... | @@ -4299,7 +4299,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4299 | 4299 | \\const a = Foo {.x = get_it()}; |
| 4300 | 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 | 4303 | , &[_][]const u8{ |
| 4304 | 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 | 4315 | \\} |
| 4316 | 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 | 4319 | , &[_][]const u8{ |
| 4320 | 4320 | "tmp.zig:6:26: error: unable to evaluate constant expression", |
| 4321 | 4321 | "tmp.zig:4:17: note: referenced here", |
| ... | ... | @@ -4344,8 +4344,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4344 | 4344 | \\ return a.* == b.*; |
| 4345 | 4345 | \\} |
| 4346 | 4346 | \\ |
| 4347 | \\export fn entry1() usize { return @sizeOf(@typeOf(bad_eql_1)); } | |
| 4348 | \\export fn entry2() usize { return @sizeOf(@typeOf(bad_eql_2)); } | |
| 4347 | \\export fn entry1() usize { return @sizeOf(@TypeOf(bad_eql_1)); } | |
| 4348 | \\export fn entry2() usize { return @sizeOf(@TypeOf(bad_eql_2)); } | |
| 4349 | 4349 | , &[_][]const u8{ |
| 4350 | 4350 | "tmp.zig:2:14: error: operator not allowed for type '[]u8'", |
| 4351 | 4351 | "tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'", |
| ... | ... | @@ -4392,7 +4392,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4392 | 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 | 4396 | , &[_][]const u8{ |
| 4397 | 4397 | "tmp.zig:3:12: error: negation caused overflow", |
| 4398 | 4398 | "tmp.zig:1:14: note: referenced here", |
| ... | ... | @@ -4404,7 +4404,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4404 | 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 | 4408 | , &[_][]const u8{ |
| 4409 | 4409 | "tmp.zig:3:14: error: operation caused overflow", |
| 4410 | 4410 | "tmp.zig:1:14: note: referenced here", |
| ... | ... | @@ -4416,7 +4416,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4416 | 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 | 4420 | , &[_][]const u8{ |
| 4421 | 4421 | "tmp.zig:3:14: error: operation caused overflow", |
| 4422 | 4422 | "tmp.zig:1:14: note: referenced here", |
| ... | ... | @@ -4428,7 +4428,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4428 | 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 | 4432 | , &[_][]const u8{ |
| 4433 | 4433 | "tmp.zig:3:14: error: operation caused overflow", |
| 4434 | 4434 | "tmp.zig:1:14: note: referenced here", |
| ... | ... | @@ -4440,7 +4440,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4440 | 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 | 4444 | , &[_][]const u8{ |
| 4445 | 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 | 4480 | \\fn f() i32 { |
| 4481 | 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 | 4484 | , &[_][]const u8{ |
| 4485 | 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 | 4524 | \\fn f(m: []const u8) void { |
| 4525 | 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 | 4528 | , &[_][]const u8{ |
| 4529 | 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 | 4537 | \\ |
| 4538 | 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 | 4541 | , &[_][]const u8{ |
| 4542 | 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 | 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 | 4600 | , &[_][]const u8{ |
| 4601 | 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 | 4655 | \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT; |
| 4656 | 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 | 4659 | , &[_][]const u8{ |
| 4660 | 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 | 4683 | \\const zero: i32 = 0; |
| 4684 | 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 | 4687 | , &[_][]const u8{ |
| 4688 | 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 | 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 | 4719 | , &[_][]const u8{ |
| 4720 | 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 | 4730 | |
| 4731 | 4731 | cases.add("global variable alignment non power of 2", |
| 4732 | 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 | 4734 | , &[_][]const u8{ |
| 4735 | 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 | 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 | 4776 | , &[_][]const u8{ |
| 4777 | 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 | 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 | 4879 | , &[_][]const u8{ |
| 4880 | 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 | 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 | 4894 | , &[_][]const u8{ |
| 4895 | 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 | 5726 | |
| 5727 | 5727 | cases.add("@ArgType arg index out of bounds", |
| 5728 | 5728 | \\comptime { |
| 5729 | \\ _ = @ArgType(@typeOf(add), 2); | |
| 5729 | \\ _ = @ArgType(@TypeOf(add), 2); | |
| 5730 | 5730 | \\} |
| 5731 | 5731 | \\fn add(a: i32, b: i32) i32 { return a + b; } |
| 5732 | 5732 | , &[_][]const u8{ |
| ... | ... | @@ -6220,7 +6220,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6220 | 6220 | cases.add("getting return type of generic function", |
| 6221 | 6221 | \\fn generic(a: var) void {} |
| 6222 | 6222 | \\comptime { |
| 6223 | \\ _ = @typeOf(generic).ReturnType; | |
| 6223 | \\ _ = @TypeOf(generic).ReturnType; | |
| 6224 | 6224 | \\} |
| 6225 | 6225 | , &[_][]const u8{ |
| 6226 | 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 | 6229 | cases.add("getting @ArgType of generic function", |
| 6230 | 6230 | \\fn generic(a: var) void {} |
| 6231 | 6231 | \\comptime { |
| 6232 | \\ _ = @ArgType(@typeOf(generic), 0); | |
| 6232 | \\ _ = @ArgType(@TypeOf(generic), 0); | |
| 6233 | 6233 | \\} |
| 6234 | 6234 | , &[_][]const u8{ |
| 6235 | 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 | 5 | var foo: u8 align(4) = 100; |
| 6 | 6 | |
| 7 | 7 | test "global variable alignment" { |
| 8 | expect(@typeOf(&foo).alignment == 4); | |
| 9 | expect(@typeOf(&foo) == *align(4) u8); | |
| 8 | expect(@TypeOf(&foo).alignment == 4); | |
| 9 | expect(@TypeOf(&foo) == *align(4) u8); | |
| 10 | 10 | const slice = @as(*[1]u8, &foo)[0..]; |
| 11 | expect(@typeOf(slice) == []align(4) u8); | |
| 11 | expect(@TypeOf(slice) == []align(4) u8); | |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | fn derp() align(@sizeOf(usize) * 2) i32 { |
| ... | ... | @@ -19,8 +19,8 @@ fn noop4() align(4) void {} |
| 19 | 19 | |
| 20 | 20 | test "function alignment" { |
| 21 | 21 | expect(derp() == 1234); |
| 22 | expect(@typeOf(noop1) == fn () align(1) void); | |
| 23 | expect(@typeOf(noop4) == fn () align(4) void); | |
| 22 | expect(@TypeOf(noop1) == fn () align(1) void); | |
| 23 | expect(@TypeOf(noop4) == fn () align(4) void); | |
| 24 | 24 | noop1(); |
| 25 | 25 | noop4(); |
| 26 | 26 | } |
| ... | ... | @@ -31,7 +31,7 @@ var baz: packed struct { |
| 31 | 31 | } = undefined; |
| 32 | 32 | |
| 33 | 33 | test "packed struct alignment" { |
| 34 | expect(@typeOf(&baz.b) == *align(1) u32); | |
| 34 | expect(@TypeOf(&baz.b) == *align(1) u32); | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | const blah: packed struct { |
| ... | ... | @@ -41,7 +41,7 @@ const blah: packed struct { |
| 41 | 41 | } = undefined; |
| 42 | 42 | |
| 43 | 43 | test "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 | } |
| 46 | 46 | |
| 47 | 47 | test "default alignment allows unspecified in type syntax" { |
| ... | ... | @@ -165,28 +165,28 @@ fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) u8 { |
| 165 | 165 | test "@ptrCast preserves alignment of bigger source" { |
| 166 | 166 | var x: u32 align(16) = 1234; |
| 167 | 167 | const ptr = @ptrCast(*u8, &x); |
| 168 | expect(@typeOf(ptr) == *align(16) u8); | |
| 168 | expect(@TypeOf(ptr) == *align(16) u8); | |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | test "runtime known array index has best alignment possible" { |
| 172 | 172 | // take full advantage of over-alignment |
| 173 | 173 | var array align(4) = [_]u8{ 1, 2, 3, 4 }; |
| 174 | expect(@typeOf(&array[0]) == *align(4) u8); | |
| 175 | expect(@typeOf(&array[1]) == *u8); | |
| 176 | expect(@typeOf(&array[2]) == *align(2) u8); | |
| 177 | expect(@typeOf(&array[3]) == *u8); | |
| 174 | expect(@TypeOf(&array[0]) == *align(4) u8); | |
| 175 | expect(@TypeOf(&array[1]) == *u8); | |
| 176 | expect(@TypeOf(&array[2]) == *align(2) u8); | |
| 177 | expect(@TypeOf(&array[3]) == *u8); | |
| 178 | 178 | |
| 179 | 179 | // because align is too small but we still figure out to use 2 |
| 180 | 180 | var bigger align(2) = [_]u64{ 1, 2, 3, 4 }; |
| 181 | expect(@typeOf(&bigger[0]) == *align(2) u64); | |
| 182 | expect(@typeOf(&bigger[1]) == *align(2) u64); | |
| 183 | expect(@typeOf(&bigger[2]) == *align(2) u64); | |
| 184 | expect(@typeOf(&bigger[3]) == *align(2) u64); | |
| 181 | expect(@TypeOf(&bigger[0]) == *align(2) u64); | |
| 182 | expect(@TypeOf(&bigger[1]) == *align(2) u64); | |
| 183 | expect(@TypeOf(&bigger[2]) == *align(2) u64); | |
| 184 | expect(@TypeOf(&bigger[3]) == *align(2) u64); | |
| 185 | 185 | |
| 186 | 186 | // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2 |
| 187 | 187 | var smaller align(2) = [_]u32{ 1, 2, 3, 4 }; |
| 188 | comptime expect(@typeOf(smaller[0..]) == []align(2) u32); | |
| 189 | comptime expect(@typeOf(smaller[0..].ptr) == [*]align(2) u32); | |
| 188 | comptime expect(@TypeOf(smaller[0..]) == []align(2) u32); | |
| 189 | comptime expect(@TypeOf(smaller[0..].ptr) == [*]align(2) u32); | |
| 190 | 190 | testIndex(smaller[0..].ptr, 0, *align(2) u32); |
| 191 | 191 | testIndex(smaller[0..].ptr, 1, *align(2) u32); |
| 192 | 192 | testIndex(smaller[0..].ptr, 2, *align(2) u32); |
| ... | ... | @@ -199,10 +199,10 @@ test "runtime known array index has best alignment possible" { |
| 199 | 199 | testIndex2(array[0..].ptr, 3, *u8); |
| 200 | 200 | } |
| 201 | 201 | fn 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 | } |
| 204 | 204 | fn 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 | } |
| 207 | 207 | |
| 208 | 208 | test "alignstack" { |
| ... | ... | @@ -303,7 +303,7 @@ test "struct field explicit alignment" { |
| 303 | 303 | var node: S.Node = undefined; |
| 304 | 304 | node.massive_byte = 100; |
| 305 | 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 | 307 | expect(@ptrToInt(&node.massive_byte) % 64 == 0); |
| 308 | 308 | } |
| 309 | 309 |
test/stage1/behavior/array.zig+3-3| ... | ... | @@ -30,7 +30,7 @@ test "void arrays" { |
| 30 | 30 | var array: [4]void = undefined; |
| 31 | 31 | array[0] = void{}; |
| 32 | 32 | array[1] = array[2]; |
| 33 | expect(@sizeOf(@typeOf(array)) == 0); | |
| 33 | expect(@sizeOf(@TypeOf(array)) == 0); | |
| 34 | 34 | expect(array.len == 4); |
| 35 | 35 | } |
| 36 | 36 | |
| ... | ... | @@ -109,12 +109,12 @@ test "array literal with specified size" { |
| 109 | 109 | |
| 110 | 110 | test "array child property" { |
| 111 | 111 | var x: [5]i32 = undefined; |
| 112 | expect(@typeOf(x).Child == i32); | |
| 112 | expect(@TypeOf(x).Child == i32); | |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | test "array len property" { |
| 116 | 116 | var x: [5]i32 = undefined; |
| 117 | expect(@typeOf(x).len == 5); | |
| 117 | expect(@TypeOf(x).len == 5); | |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | test "array len field" { |
test/stage1/behavior/async_fn.zig+12-12| ... | ... | @@ -185,7 +185,7 @@ var a_promise: anyframe = undefined; |
| 185 | 185 | var global_result = false; |
| 186 | 186 | async fn testSuspendBlock() void { |
| 187 | 187 | suspend { |
| 188 | comptime expect(@typeOf(@frame()) == *@Frame(testSuspendBlock)); | |
| 188 | comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock)); | |
| 189 | 189 | a_promise = @frame(); |
| 190 | 190 | } |
| 191 | 191 | |
| ... | ... | @@ -282,7 +282,7 @@ test "async fn pointer in a struct field" { |
| 282 | 282 | var foo = Foo{ .bar = simpleAsyncFn2 }; |
| 283 | 283 | var bytes: [64]u8 align(16) = undefined; |
| 284 | 284 | const f = @asyncCall(&bytes, {}, foo.bar, &data); |
| 285 | comptime expect(@typeOf(f) == anyframe->void); | |
| 285 | comptime expect(@TypeOf(f) == anyframe->void); | |
| 286 | 286 | expect(data == 2); |
| 287 | 287 | resume f; |
| 288 | 288 | expect(data == 4); |
| ... | ... | @@ -332,7 +332,7 @@ test "async fn with inferred error set" { |
| 332 | 332 | fn doTheTest() void { |
| 333 | 333 | var frame: [1]@Frame(middle) = undefined; |
| 334 | 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 | 336 | _ = @asyncCall(@sliceToBytes(frame[0..]), &result, fn_ptr); |
| 337 | 337 | resume global_frame; |
| 338 | 338 | std.testing.expectError(error.Fail, result); |
| ... | ... | @@ -952,7 +952,7 @@ test "@asyncCall with comptime-known function, but not awaited directly" { |
| 952 | 952 | |
| 953 | 953 | fn doTheTest() void { |
| 954 | 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 | 956 | _ = @asyncCall(@sliceToBytes(frame[0..]), &result, middle); |
| 957 | 957 | resume global_frame; |
| 958 | 958 | std.testing.expectError(error.Fail, result); |
| ... | ... | @@ -1009,7 +1009,7 @@ test "@asyncCall using the result location inside the frame" { |
| 1009 | 1009 | var foo = Foo{ .bar = S.simple2 }; |
| 1010 | 1010 | var bytes: [64]u8 align(16) = undefined; |
| 1011 | 1011 | const f = @asyncCall(&bytes, {}, foo.bar, &data); |
| 1012 | comptime expect(@typeOf(f) == anyframe->i32); | |
| 1012 | comptime expect(@TypeOf(f) == anyframe->i32); | |
| 1013 | 1013 | expect(data == 2); |
| 1014 | 1014 | resume f; |
| 1015 | 1015 | expect(data == 4); |
| ... | ... | @@ -1017,18 +1017,18 @@ test "@asyncCall using the result location inside the frame" { |
| 1017 | 1017 | expect(data == 1234); |
| 1018 | 1018 | } |
| 1019 | 1019 | |
| 1020 | test "@typeOf an async function call of generic fn with error union type" { | |
| 1020 | test "@TypeOf an async function call of generic fn with error union type" { | |
| 1021 | 1021 | const S = struct { |
| 1022 | 1022 | fn func(comptime x: var) anyerror!i32 { |
| 1023 | const T = @typeOf(async func(x)); | |
| 1024 | comptime expect(T == @typeOf(@frame()).Child); | |
| 1023 | const T = @TypeOf(async func(x)); | |
| 1024 | comptime expect(T == @TypeOf(@frame()).Child); | |
| 1025 | 1025 | return undefined; |
| 1026 | 1026 | } |
| 1027 | 1027 | }; |
| 1028 | 1028 | _ = async S.func(i32); |
| 1029 | 1029 | } |
| 1030 | 1030 | |
| 1031 | test "using @typeOf on a generic function call" { | |
| 1031 | test "using @TypeOf on a generic function call" { | |
| 1032 | 1032 | const S = struct { |
| 1033 | 1033 | var global_frame: anyframe = undefined; |
| 1034 | 1034 | var global_ok = false; |
| ... | ... | @@ -1043,7 +1043,7 @@ test "using @typeOf on a generic function call" { |
| 1043 | 1043 | suspend { |
| 1044 | 1044 | global_frame = @frame(); |
| 1045 | 1045 | } |
| 1046 | const F = @typeOf(async amain(x - 1)); | |
| 1046 | const F = @TypeOf(async amain(x - 1)); | |
| 1047 | 1047 | const frame = @intToPtr(*F, @ptrToInt(&buf)); |
| 1048 | 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 | 1068 | suspend { |
| 1069 | 1069 | global_frame = @frame(); |
| 1070 | 1070 | } |
| 1071 | const F = @typeOf(async amain(x - 1)); | |
| 1071 | const F = @TypeOf(async amain(x - 1)); | |
| 1072 | 1072 | const frame = @intToPtr(*F, @ptrToInt(&buf)); |
| 1073 | 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 | 1080 | }; |
| 1081 | 1081 | }; |
| 1082 | 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 | 1084 | _ = @asyncCall(&frame, &res, S.amain, @as(u32, 1)); |
| 1085 | 1085 | resume S.global_frame; |
| 1086 | 1086 | expect(S.global_ok); |
test/stage1/behavior/atomics.zig+2-2| ... | ... | @@ -118,7 +118,7 @@ test "atomic load and rmw with enum" { |
| 118 | 118 | |
| 119 | 119 | expect(@atomicLoad(Value, &x, .SeqCst) != .b); |
| 120 | 120 | |
| 121 | _ = @atomicRmw(Value, &x, .Xchg, .c, .SeqCst); | |
| 121 | _ = @atomicRmw(Value, &x, .Xchg, .c, .SeqCst); | |
| 122 | 122 | expect(@atomicLoad(Value, &x, .SeqCst) == .c); |
| 123 | 123 | expect(@atomicLoad(Value, &x, .SeqCst) != .a); |
| 124 | 124 | expect(@atomicLoad(Value, &x, .SeqCst) != .b); |
| ... | ... | @@ -143,4 +143,4 @@ fn testAtomicStore() void { |
| 143 | 143 | expect(@atomicLoad(u32, &x, .SeqCst) == 1); |
| 144 | 144 | @atomicStore(u32, &x, 12345678, .SeqCst); |
| 145 | 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 | 15 | x[1] = 0xFFFFFF; |
| 16 | 16 | |
| 17 | 17 | const bytes = @sliceToBytes(x); |
| 18 | expect(@typeOf(bytes) == []align(4) u8); | |
| 18 | expect(@TypeOf(bytes) == []align(4) u8); | |
| 19 | 19 | expect(bytes.len == 8); |
| 20 | 20 | |
| 21 | 21 | for (bytes) |*b| { |
test/stage1/behavior/bugs/2114.zig+1-1| ... | ... | @@ -3,7 +3,7 @@ const expect = std.testing.expect; |
| 3 | 3 | const math = std.math; |
| 4 | 4 | |
| 5 | 5 | fn ctz(x: var) usize { |
| 6 | return @ctz(@typeOf(x), x); | |
| 6 | return @ctz(@TypeOf(x), x); | |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | test "fixed" { |
test/stage1/behavior/bugs/3742.zig+1-1| ... | ... | @@ -24,7 +24,7 @@ pub fn isCommand(comptime T: type) bool { |
| 24 | 24 | |
| 25 | 25 | pub const ArgSerializer = struct { |
| 26 | 26 | pub fn serializeCommand(command: var) void { |
| 27 | const CmdT = @typeOf(command); | |
| 27 | const CmdT = @TypeOf(command); | |
| 28 | 28 | |
| 29 | 29 | if (comptime isCommand(CmdT)) { |
| 30 | 30 | // 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 | 3 | |
| 4 | 4 | test "function with *const parameter with type dereferenced by namespace" { |
| 5 | 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 | 7 | foo(&x); |
| 8 | 8 | } |
| 9 | 9 |
test/stage1/behavior/bugs/718.zig+1-1| ... | ... | @@ -9,7 +9,7 @@ const Keys = struct { |
| 9 | 9 | }; |
| 10 | 10 | var keys: Keys = undefined; |
| 11 | 11 | test "zero keys with @memset" { |
| 12 | @memset(@ptrCast([*]u8, &keys), 0, @sizeOf(@typeOf(keys))); | |
| 12 | @memset(@ptrCast([*]u8, &keys), 0, @sizeOf(@TypeOf(keys))); | |
| 13 | 13 | expect(!keys.up); |
| 14 | 14 | expect(!keys.down); |
| 15 | 15 | expect(!keys.left); |
test/stage1/behavior/cast.zig+10-10| ... | ... | @@ -226,14 +226,14 @@ fn testCastConstArrayRefToConstSlice() void { |
| 226 | 226 | { |
| 227 | 227 | const blah = "aoeu".*; |
| 228 | 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 | 230 | const slice: []const u8 = const_array_ref; |
| 231 | 231 | expect(mem.eql(u8, slice, "aoeu")); |
| 232 | 232 | } |
| 233 | 233 | { |
| 234 | 234 | const blah: [4]u8 = "aoeu".*; |
| 235 | 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 | 237 | const slice: []const u8 = const_array_ref; |
| 238 | 238 | expect(mem.eql(u8, slice, "aoeu")); |
| 239 | 239 | } |
| ... | ... | @@ -353,29 +353,29 @@ test "cast *[1][*]const u8 to [*]const ?[*]const u8" { |
| 353 | 353 | |
| 354 | 354 | test "@intCast comptime_int" { |
| 355 | 355 | const result = @intCast(i32, 1234); |
| 356 | expect(@typeOf(result) == i32); | |
| 356 | expect(@TypeOf(result) == i32); | |
| 357 | 357 | expect(result == 1234); |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | test "@floatCast comptime_int and comptime_float" { |
| 361 | 361 | { |
| 362 | 362 | const result = @floatCast(f16, 1234); |
| 363 | expect(@typeOf(result) == f16); | |
| 363 | expect(@TypeOf(result) == f16); | |
| 364 | 364 | expect(result == 1234.0); |
| 365 | 365 | } |
| 366 | 366 | { |
| 367 | 367 | const result = @floatCast(f16, 1234.0); |
| 368 | expect(@typeOf(result) == f16); | |
| 368 | expect(@TypeOf(result) == f16); | |
| 369 | 369 | expect(result == 1234.0); |
| 370 | 370 | } |
| 371 | 371 | { |
| 372 | 372 | const result = @floatCast(f32, 1234); |
| 373 | expect(@typeOf(result) == f32); | |
| 373 | expect(@TypeOf(result) == f32); | |
| 374 | 374 | expect(result == 1234.0); |
| 375 | 375 | } |
| 376 | 376 | { |
| 377 | 377 | const result = @floatCast(f32, 1234.0); |
| 378 | expect(@typeOf(result) == f32); | |
| 378 | expect(@TypeOf(result) == f32); | |
| 379 | 379 | expect(result == 1234.0); |
| 380 | 380 | } |
| 381 | 381 | } |
| ... | ... | @@ -383,12 +383,12 @@ test "@floatCast comptime_int and comptime_float" { |
| 383 | 383 | test "comptime_int @intToFloat" { |
| 384 | 384 | { |
| 385 | 385 | const result = @intToFloat(f16, 1234); |
| 386 | expect(@typeOf(result) == f16); | |
| 386 | expect(@TypeOf(result) == f16); | |
| 387 | 387 | expect(result == 1234.0); |
| 388 | 388 | } |
| 389 | 389 | { |
| 390 | 390 | const result = @intToFloat(f32, 1234); |
| 391 | expect(@typeOf(result) == f32); | |
| 391 | expect(@TypeOf(result) == f32); | |
| 392 | 392 | expect(result == 1234.0); |
| 393 | 393 | } |
| 394 | 394 | } |
| ... | ... | @@ -396,7 +396,7 @@ test "comptime_int @intToFloat" { |
| 396 | 396 | test "@bytesToSlice keeps pointer alignment" { |
| 397 | 397 | var bytes = [_]u8{ 0x01, 0x02, 0x03, 0x04 }; |
| 398 | 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 | } |
| 401 | 401 | |
| 402 | 402 | test "@intCast i32 to u7" { |
test/stage1/behavior/error.zig+3-3| ... | ... | @@ -83,9 +83,9 @@ test "error union type " { |
| 83 | 83 | fn testErrorUnionType() void { |
| 84 | 84 | const x: anyerror!i32 = 1234; |
| 85 | 85 | if (x) |value| expect(value == 1234) else |_| unreachable; |
| 86 | expect(@typeId(@typeOf(x)) == builtin.TypeId.ErrorUnion); | |
| 87 | expect(@typeId(@typeOf(x).ErrorSet) == builtin.TypeId.ErrorSet); | |
| 88 | expect(@typeOf(x).ErrorSet == anyerror); | |
| 86 | expect(@typeId(@TypeOf(x)) == builtin.TypeId.ErrorUnion); | |
| 87 | expect(@typeId(@TypeOf(x).ErrorSet) == builtin.TypeId.ErrorSet); | |
| 88 | expect(@TypeOf(x).ErrorSet == anyerror); | |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | test "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 | 105 | |
| 106 | 106 | test "constant expressions" { |
| 107 | 107 | var array: [array_size]u8 = undefined; |
| 108 | expect(@sizeOf(@typeOf(array)) == 20); | |
| 108 | expect(@sizeOf(@TypeOf(array)) == 20); | |
| 109 | 109 | } |
| 110 | 110 | const array_size: u8 = 20; |
| 111 | 111 | |
| ... | ... | @@ -598,7 +598,7 @@ test "pointer to type" { |
| 598 | 598 | var T: type = i32; |
| 599 | 599 | expect(T == i32); |
| 600 | 600 | var ptr = &T; |
| 601 | expect(@typeOf(ptr) == *type); | |
| 601 | expect(@TypeOf(ptr) == *type); | |
| 602 | 602 | ptr.* = f32; |
| 603 | 603 | expect(T == f32); |
| 604 | 604 | expect(*T == *f32); |
test/stage1/behavior/fn.zig+4-4| ... | ... | @@ -73,7 +73,7 @@ fn fnWithUnreachable() noreturn { |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | test "function pointers" { |
| 76 | const fns = [_]@typeOf(fn1){ | |
| 76 | const fns = [_]@TypeOf(fn1){ | |
| 77 | 77 | fn1, |
| 78 | 78 | fn2, |
| 79 | 79 | fn3, |
| ... | ... | @@ -130,7 +130,7 @@ test "pass by non-copying value through var arg" { |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | fn addPointCoordsVar(pt: var) i32 { |
| 133 | comptime expect(@typeOf(pt) == Point); | |
| 133 | comptime expect(@TypeOf(pt) == Point); | |
| 134 | 134 | return pt.x + pt.y; |
| 135 | 135 | } |
| 136 | 136 | |
| ... | ... | @@ -170,7 +170,7 @@ test "pass by non-copying value as method, at comptime" { |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | fn outer(y: u32) fn (u32) u32 { |
| 173 | const Y = @typeOf(y); | |
| 173 | const Y = @TypeOf(y); | |
| 174 | 174 | const st = struct { |
| 175 | 175 | fn get(z: u32) u32 { |
| 176 | 176 | return z + @sizeOf(Y); |
| ... | ... | @@ -265,7 +265,7 @@ test "ability to give comptime types and non comptime types to same parameter" { |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 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 | 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 | 29 | expect(mem.eql(u8, &target, "bcdefgh")); |
| 30 | 30 | |
| 31 | 31 | for (source) |*c, i| |
| 32 | expect(@typeOf(c) == *const u8); | |
| 32 | expect(@TypeOf(c) == *const u8); | |
| 33 | 33 | for (target) |*c, i| |
| 34 | expect(@typeOf(c) == *u8); | |
| 34 | expect(@TypeOf(c) == *u8); | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | fn mangleString(s: []u8) void { |
test/stage1/behavior/generics.zig+1-1| ... | ... | @@ -47,7 +47,7 @@ comptime { |
| 47 | 47 | expect(max_f64(1.2, 3.4) == 3.4); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | fn max_var(a: var, b: var) @typeOf(a + b) { | |
| 50 | fn max_var(a: var, b: var) @TypeOf(a + b) { | |
| 51 | 51 | return if (a > b) a else b; |
| 52 | 52 | } |
| 53 | 53 |
test/stage1/behavior/math.zig+3-3| ... | ... | @@ -281,8 +281,8 @@ test "small int addition" { |
| 281 | 281 | x += 1; |
| 282 | 282 | expect(x == 3); |
| 283 | 283 | |
| 284 | var result: @typeOf(x) = 3; | |
| 285 | expect(@addWithOverflow(@typeOf(x), x, 1, &result)); | |
| 284 | var result: @TypeOf(x) = 3; | |
| 285 | expect(@addWithOverflow(@TypeOf(x), x, 1, &result)); | |
| 286 | 286 | |
| 287 | 287 | expect(result == 0); |
| 288 | 288 | } |
| ... | ... | @@ -586,7 +586,7 @@ test "@sqrt" { |
| 586 | 586 | |
| 587 | 587 | const x = 14.0; |
| 588 | 588 | const y = x * x; |
| 589 | const z = @sqrt(@typeOf(y), y); | |
| 589 | const z = @sqrt(@TypeOf(y), y); | |
| 590 | 590 | comptime expect(z == x); |
| 591 | 591 | } |
| 592 | 592 |
test/stage1/behavior/misc.zig+10-10| ... | ... | @@ -362,8 +362,8 @@ test "string concatenation" { |
| 362 | 362 | const a = "OK" ++ " IT " ++ "WORKED"; |
| 363 | 363 | const b = "OK IT WORKED"; |
| 364 | 364 | |
| 365 | comptime expect(@typeOf(a) == *const [12:0]u8); | |
| 366 | comptime expect(@typeOf(b) == *const [12:0]u8); | |
| 365 | comptime expect(@TypeOf(a) == *const [12:0]u8); | |
| 366 | comptime expect(@TypeOf(b) == *const [12:0]u8); | |
| 367 | 367 | |
| 368 | 368 | const len = mem.len(u8, b); |
| 369 | 369 | const len_with_null = len + 1; |
| ... | ... | @@ -460,19 +460,19 @@ test "@typeId" { |
| 460 | 460 | expect(@typeId(*f32) == Tid.Pointer); |
| 461 | 461 | expect(@typeId([2]u8) == Tid.Array); |
| 462 | 462 | expect(@typeId(AStruct) == Tid.Struct); |
| 463 | expect(@typeId(@typeOf(1)) == Tid.ComptimeInt); | |
| 464 | expect(@typeId(@typeOf(1.0)) == Tid.ComptimeFloat); | |
| 465 | expect(@typeId(@typeOf(undefined)) == Tid.Undefined); | |
| 466 | expect(@typeId(@typeOf(null)) == Tid.Null); | |
| 463 | expect(@typeId(@TypeOf(1)) == Tid.ComptimeInt); | |
| 464 | expect(@typeId(@TypeOf(1.0)) == Tid.ComptimeFloat); | |
| 465 | expect(@typeId(@TypeOf(undefined)) == Tid.Undefined); | |
| 466 | expect(@typeId(@TypeOf(null)) == Tid.Null); | |
| 467 | 467 | expect(@typeId(?i32) == Tid.Optional); |
| 468 | 468 | expect(@typeId(anyerror!i32) == Tid.ErrorUnion); |
| 469 | 469 | expect(@typeId(anyerror) == Tid.ErrorSet); |
| 470 | 470 | expect(@typeId(AnEnum) == Tid.Enum); |
| 471 | expect(@typeId(@typeOf(AUnionEnum.One)) == Tid.Enum); | |
| 471 | expect(@typeId(@TypeOf(AUnionEnum.One)) == Tid.Enum); | |
| 472 | 472 | expect(@typeId(AUnionEnum) == Tid.Union); |
| 473 | 473 | expect(@typeId(AUnion) == Tid.Union); |
| 474 | 474 | expect(@typeId(fn () void) == Tid.Fn); |
| 475 | expect(@typeId(@typeOf(builtin)) == Tid.Type); | |
| 475 | expect(@typeId(@TypeOf(builtin)) == Tid.Type); | |
| 476 | 476 | // TODO bound fn |
| 477 | 477 | // TODO arg tuple |
| 478 | 478 | // TODO opaque |
| ... | ... | @@ -652,9 +652,9 @@ test "volatile load and store" { |
| 652 | 652 | |
| 653 | 653 | test "slice string literal has type []const u8" { |
| 654 | 654 | comptime { |
| 655 | expect(@typeOf("aoeu"[0..]) == []const u8); | |
| 655 | expect(@TypeOf("aoeu"[0..]) == []const u8); | |
| 656 | 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 | } |
| 660 | 660 |
test/stage1/behavior/pointers.zig+17-13| ... | ... | @@ -93,10 +93,10 @@ test "peer type resolution with C pointers" { |
| 93 | 93 | var x2 = if (t) ptr_many else ptr_c; |
| 94 | 94 | var x3 = if (t) ptr_c else ptr_one; |
| 95 | 95 | var x4 = if (t) ptr_c else ptr_many; |
| 96 | expect(@typeOf(x1) == [*c]u8); | |
| 97 | expect(@typeOf(x2) == [*c]u8); | |
| 98 | expect(@typeOf(x3) == [*c]u8); | |
| 99 | expect(@typeOf(x4) == [*c]u8); | |
| 96 | expect(@TypeOf(x1) == [*c]u8); | |
| 97 | expect(@TypeOf(x2) == [*c]u8); | |
| 98 | expect(@TypeOf(x3) == [*c]u8); | |
| 99 | expect(@TypeOf(x4) == [*c]u8); | |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | test "implicit casting between C pointer and optional non-C pointer" { |
| ... | ... | @@ -144,11 +144,11 @@ test "allowzero pointer and slice" { |
| 144 | 144 | expect(opt_ptr != null); |
| 145 | 145 | expect(@ptrToInt(ptr) == 0); |
| 146 | 146 | var slice = ptr[0..10]; |
| 147 | expect(@typeOf(slice) == []allowzero i32); | |
| 147 | expect(@TypeOf(slice) == []allowzero i32); | |
| 148 | 148 | expect(@ptrToInt(&slice[5]) == 20); |
| 149 | 149 | |
| 150 | expect(@typeInfo(@typeOf(ptr)).Pointer.is_allowzero); | |
| 151 | expect(@typeInfo(@typeOf(slice)).Pointer.is_allowzero); | |
| 150 | expect(@typeInfo(@TypeOf(ptr)).Pointer.is_allowzero); | |
| 151 | expect(@typeInfo(@TypeOf(slice)).Pointer.is_allowzero); | |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | 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" { |
| 204 | 204 | test "null terminated pointer" { |
| 205 | 205 | const S = struct { |
| 206 | 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 | 208 | var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero); |
| 209 | 209 | var no_zero_ptr: [*]const u8 = zero_ptr; |
| 210 | 210 | var zero_ptr_again = @ptrCast([*:0]const u8, no_zero_ptr); |
| ... | ... | @@ -218,7 +218,7 @@ test "null terminated pointer" { |
| 218 | 218 | test "allow any sentinel" { |
| 219 | 219 | const S = struct { |
| 220 | 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 | 222 | var ptr: [*:std.math.minInt(i32)]i32 = &array; |
| 223 | 223 | expect(ptr[4] == std.math.minInt(i32)); |
| 224 | 224 | } |
| ... | ... | @@ -229,10 +229,14 @@ test "allow any sentinel" { |
| 229 | 229 | |
| 230 | 230 | test "pointer sentinel with enums" { |
| 231 | 231 | const S = struct { |
| 232 | const Number = enum{one, two, sentinel}; | |
| 232 | const Number = enum { | |
| 233 | one, | |
| 234 | two, | |
| 235 | sentinel, | |
| 236 | }; | |
| 233 | 237 | |
| 234 | 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 | 240 | 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 | 247 | test "pointer sentinel with optional element" { |
| 244 | 248 | const S = struct { |
| 245 | 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 | 251 | 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 | 259 | const S = struct { |
| 256 | 260 | fn doTheTest() void { |
| 257 | 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 | 263 | 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 | 55 | comptime { |
| 56 | 56 | const a: u32 = 1234; |
| 57 | 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 | } |
| 61 | 61 |
test/stage1/behavior/reflection.zig+6-6| ... | ... | @@ -13,12 +13,12 @@ test "reflection: array, pointer, optional, error union type child" { |
| 13 | 13 | |
| 14 | 14 | test "reflection: function return type, var args, and param types" { |
| 15 | 15 | comptime { |
| 16 | expect(@typeOf(dummy).ReturnType == i32); | |
| 17 | expect(!@typeOf(dummy).is_var_args); | |
| 18 | expect(@typeOf(dummy).arg_count == 3); | |
| 19 | expect(@ArgType(@typeOf(dummy), 0) == bool); | |
| 20 | expect(@ArgType(@typeOf(dummy), 1) == i32); | |
| 21 | expect(@ArgType(@typeOf(dummy), 2) == f32); | |
| 16 | expect(@TypeOf(dummy).ReturnType == i32); | |
| 17 | expect(!@TypeOf(dummy).is_var_args); | |
| 18 | expect(@TypeOf(dummy).arg_count == 3); | |
| 19 | expect(@ArgType(@TypeOf(dummy), 0) == bool); | |
| 20 | expect(@ArgType(@TypeOf(dummy), 1) == i32); | |
| 21 | expect(@ArgType(@TypeOf(dummy), 2) == f32); | |
| 22 | 22 | } |
| 23 | 23 | } |
| 24 | 24 |
test/stage1/behavior/sizeof_and_typeof.zig+10-10| ... | ... | @@ -1,12 +1,12 @@ |
| 1 | 1 | const builtin = @import("builtin"); |
| 2 | 2 | const expect = @import("std").testing.expect; |
| 3 | 3 | |
| 4 | test "@sizeOf and @typeOf" { | |
| 5 | const y: @typeOf(x) = 120; | |
| 6 | expect(@sizeOf(@typeOf(y)) == 2); | |
| 4 | test "@sizeOf and @TypeOf" { | |
| 5 | const y: @TypeOf(x) = 120; | |
| 6 | expect(@sizeOf(@TypeOf(y)) == 2); | |
| 7 | 7 | } |
| 8 | 8 | const x: u16 = 13; |
| 9 | const z: @typeOf(x) = 19; | |
| 9 | const z: @TypeOf(x) = 19; | |
| 10 | 10 | |
| 11 | 11 | const A = struct { |
| 12 | 12 | a: u8, |
| ... | ... | @@ -71,8 +71,8 @@ test "@bitOffsetOf" { |
| 71 | 71 | test "@sizeOf on compile-time types" { |
| 72 | 72 | expect(@sizeOf(comptime_int) == 0); |
| 73 | 73 | expect(@sizeOf(comptime_float) == 0); |
| 74 | expect(@sizeOf(@typeOf(.hi)) == 0); | |
| 75 | expect(@sizeOf(@typeOf(type)) == 0); | |
| 74 | expect(@sizeOf(@TypeOf(.hi)) == 0); | |
| 75 | expect(@sizeOf(@TypeOf(type)) == 0); | |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | 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 | 90 | expect(@sizeOf(S.Bar) == 8); |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | test "@typeOf() has no runtime side effects" { | |
| 93 | test "@TypeOf() has no runtime side effects" { | |
| 94 | 94 | const S = struct { |
| 95 | 95 | fn foo(comptime T: type, ptr: *T) T { |
| 96 | 96 | ptr.* += 1; |
| ... | ... | @@ -98,12 +98,12 @@ test "@typeOf() has no runtime side effects" { |
| 98 | 98 | } |
| 99 | 99 | }; |
| 100 | 100 | var data: i32 = 0; |
| 101 | const T = @typeOf(S.foo(i32, &data)); | |
| 101 | const T = @TypeOf(S.foo(i32, &data)); | |
| 102 | 102 | comptime expect(T == i32); |
| 103 | 103 | expect(data == 0); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | test "branching logic inside @typeOf" { | |
| 106 | test "branching logic inside @TypeOf" { | |
| 107 | 107 | const S = struct { |
| 108 | 108 | var data: i32 = 0; |
| 109 | 109 | fn foo() anyerror!i32 { |
| ... | ... | @@ -111,7 +111,7 @@ test "branching logic inside @typeOf" { |
| 111 | 111 | return undefined; |
| 112 | 112 | } |
| 113 | 113 | }; |
| 114 | const T = @typeOf(S.foo() catch undefined); | |
| 114 | const T = @TypeOf(S.foo() catch undefined); | |
| 115 | 115 | comptime expect(T == i32); |
| 116 | 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 | 406 | fn doTheSwitch1(u: Union) void { |
| 407 | 407 | switch (u) { |
| 408 | 408 | .A, .C => |e| { |
| 409 | expect(@typeOf(e) == usize); | |
| 409 | expect(@TypeOf(e) == usize); | |
| 410 | 410 | expect(e == 8); |
| 411 | 411 | }, |
| 412 | 412 | .B => |e| @panic("fail"), |
| ... | ... | @@ -416,7 +416,7 @@ test "switch prongs with cases with identical payload types" { |
| 416 | 416 | switch (u) { |
| 417 | 417 | .A, .C => |e| @panic("fail"), |
| 418 | 418 | .B => |e| { |
| 419 | expect(@typeOf(e) == isize); | |
| 419 | expect(@TypeOf(e) == isize); | |
| 420 | 420 | expect(e == -8); |
| 421 | 421 | }, |
| 422 | 422 | } |
test/stage1/behavior/type.zig+2-2| ... | ... | @@ -125,10 +125,10 @@ test "Type.ComptimeInt" { |
| 125 | 125 | testTypes(&[_]type{comptime_int}); |
| 126 | 126 | } |
| 127 | 127 | test "Type.Undefined" { |
| 128 | testTypes(&[_]type{@typeOf(undefined)}); | |
| 128 | testTypes(&[_]type{@TypeOf(undefined)}); | |
| 129 | 129 | } |
| 130 | 130 | test "Type.Null" { |
| 131 | testTypes(&[_]type{@typeOf(null)}); | |
| 131 | testTypes(&[_]type{@TypeOf(null)}); | |
| 132 | 132 | } |
| 133 | 133 | test "@Type create slice with null sentinel" { |
| 134 | 134 | const Slice = @Type(builtin.TypeInfo{ |
test/stage1/behavior/type_info.zig+3-3| ... | ... | @@ -201,7 +201,7 @@ fn testUnion() void { |
| 201 | 201 | expect(typeinfo_info.Union.fields.len == 25); |
| 202 | 202 | expect(typeinfo_info.Union.fields[4].enum_field != null); |
| 203 | 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 | 205 | expect(typeinfo_info.Union.decls.len == 21); |
| 206 | 206 | |
| 207 | 207 | const TestNoTagUnion = union { |
| ... | ... | @@ -264,7 +264,7 @@ test "type info: function type info" { |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | fn testFunction() void { |
| 267 | const fn_info = @typeInfo(@typeOf(foo)); | |
| 267 | const fn_info = @typeInfo(@TypeOf(foo)); | |
| 268 | 268 | expect(@as(TypeId, fn_info) == TypeId.Fn); |
| 269 | 269 | expect(fn_info.Fn.calling_convention == TypeInfo.CallingConvention.Unspecified); |
| 270 | 270 | expect(fn_info.Fn.is_generic); |
| ... | ... | @@ -273,7 +273,7 @@ fn testFunction() void { |
| 273 | 273 | expect(fn_info.Fn.return_type == null); |
| 274 | 274 | |
| 275 | 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 | 277 | expect(@as(TypeId, bound_fn_info) == TypeId.BoundFn); |
| 278 | 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 | 64 | |
| 65 | 65 | test "type name of undefined" { |
| 66 | 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 | 148 | fn doTheTest() void { |
| 149 | 149 | var v: u32 = 5; |
| 150 | 150 | var x = @splat(4, v); |
| 151 | expect(@typeOf(x) == @Vector(4, u32)); | |
| 151 | expect(@TypeOf(x) == @Vector(4, u32)); | |
| 152 | 152 | var array_x: [4]u32 = x; |
| 153 | 153 | expect(array_x[0] == 5); |
| 154 | 154 | expect(array_x[1] == 5); |
test/translate_c.zig+1-1| ... | ... | @@ -1539,7 +1539,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 1539 | 1539 | cases.add("macro pointer cast", |
| 1540 | 1540 | \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE) |
| 1541 | 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 | }); |
| 1544 | 1544 | |
| 1545 | 1545 | cases.add("if on non-bool", |
tools/merge_anal_dumps.zig+1-1| ... | ... | @@ -311,7 +311,7 @@ const Dump = struct { |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 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 | 315 | try jw.beginObject(); |
| 316 | 316 | |
| 317 | 317 | try jw.objectField("typeKinds"); |