| ... | ... | @@ -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 | } |