authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2019-12-09 21:59:42+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-10 11:09:41-05:00
log30715560c829d5636734edf7eabff3ee4d170e5d
tree6b4fd0751e80a9c4128756d59d3c0bfecd230498
parent8c096707b784b3f7f8e1f8381e07d37724263083
signature Commit is signed but in an unrecognized format.

Rename @typeOf to @TypeOf in the language reference


1 files changed, 52 insertions(+), 52 deletions(-)

doc/langref.html.in+52-52
......@@ -307,7 +307,7 @@ pub fn main() void {
307307 assert(optional_value == null);
308308
309309 warn("\noptional 1\ntype: {}\nvalue: {}\n", .{
310 @typeName(@typeOf(optional_value)),
310 @typeName(@TypeOf(optional_value)),
311311 optional_value,
312312 });
313313
......@@ -315,7 +315,7 @@ pub fn main() void {
315315 assert(optional_value != null);
316316
317317 warn("\noptional 2\ntype: {}\nvalue: {}\n", .{
318 @typeName(@typeOf(optional_value)),
318 @typeName(@TypeOf(optional_value)),
319319 optional_value,
320320 });
321321
......@@ -323,14 +323,14 @@ pub fn main() void {
323323 var number_or_error: anyerror!i32 = error.ArgNotFound;
324324
325325 warn("\nerror union 1\ntype: {}\nvalue: {}\n", .{
326 @typeName(@typeOf(number_or_error)),
326 @typeName(@TypeOf(number_or_error)),
327327 number_or_error,
328328 });
329329
330330 number_or_error = 1234;
331331
332332 warn("\nerror union 2\ntype: {}\nvalue: {}\n", .{
333 @typeName(@typeOf(number_or_error)),
333 @typeName(@TypeOf(number_or_error)),
334334 number_or_error,
335335 });
336336}
......@@ -572,7 +572,7 @@ const mem = @import("std").mem;
572572
573573test "string literals" {
574574 const bytes = "hello";
575 assert(@typeOf(bytes) == *const [5:0]u8);
575 assert(@TypeOf(bytes) == *const [5:0]u8);
576576 assert(bytes.len == 5);
577577 assert(bytes[1] == 'e');
578578 assert(bytes[5] == 0);
......@@ -1802,7 +1802,7 @@ const assert = std.debug.assert;
18021802test "null terminated array" {
18031803 const array = [_:0]u8 {1, 2, 3, 4};
18041804
1805 assert(@typeOf(array) == [4:0]u8);
1805 assert(@TypeOf(array) == [4:0]u8);
18061806 assert(array.len == 4);
18071807 assert(array[4] == 0);
18081808}
......@@ -1885,12 +1885,12 @@ test "address of syntax" {
18851885 assert(x_ptr.* == 1234);
18861886
18871887 // When you get the address of a const variable, you get a const pointer to a single item.
1888 assert(@typeOf(x_ptr) == *const i32);
1888 assert(@TypeOf(x_ptr) == *const i32);
18891889
18901890 // If you want to mutate the value, you'd need an address of a mutable variable:
18911891 var y: i32 = 5678;
18921892 const y_ptr = &y;
1893 assert(@typeOf(y_ptr) == *i32);
1893 assert(@TypeOf(y_ptr) == *i32);
18941894 y_ptr.* += 1;
18951895 assert(y_ptr.* == 5679);
18961896}
......@@ -1901,7 +1901,7 @@ test "pointer array access" {
19011901 // does not support pointer arithmetic.
19021902 var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
19031903 const ptr = &array[2];
1904 assert(@typeOf(ptr) == *u8);
1904 assert(@TypeOf(ptr) == *u8);
19051905
19061906 assert(array[2] == 3);
19071907 ptr.* += 1;
......@@ -1953,7 +1953,7 @@ const assert = @import("std").debug.assert;
19531953test "@ptrToInt and @intToPtr" {
19541954 const ptr = @intToPtr(*i32, 0xdeadbeef);
19551955 const addr = @ptrToInt(ptr);
1956 assert(@typeOf(addr) == usize);
1956 assert(@TypeOf(addr) == usize);
19571957 assert(addr == 0xdeadbeef);
19581958}
19591959 {#code_end#}
......@@ -1968,7 +1968,7 @@ test "comptime @intToPtr" {
19681968 // ptr is never dereferenced.
19691969 const ptr = @intToPtr(*i32, 0xdeadbeef);
19701970 const addr = @ptrToInt(ptr);
1971 assert(@typeOf(addr) == usize);
1971 assert(@TypeOf(addr) == usize);
19721972 assert(addr == 0xdeadbeef);
19731973 }
19741974}
......@@ -1984,7 +1984,7 @@ const assert = @import("std").debug.assert;
19841984
19851985test "volatile" {
19861986 const mmio_ptr = @intToPtr(*volatile u8, 0x12345678);
1987 assert(@typeOf(mmio_ptr) == *volatile u8);
1987 assert(@TypeOf(mmio_ptr) == *volatile u8);
19881988}
19891989 {#code_end#}
19901990 <p>
......@@ -2041,8 +2041,8 @@ const builtin = @import("builtin");
20412041
20422042test "variable alignment" {
20432043 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);
20462046 assert(*i32 == *align(align_of_i32) i32);
20472047 if (builtin.arch == builtin.Arch.x86_64) {
20482048 assert((*i32).alignment == 4);
......@@ -2063,10 +2063,10 @@ const assert = @import("std").debug.assert;
20632063var foo: u8 align(4) = 100;
20642064
20652065test "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);
20682068 const slice = @as(*[1]u8, &foo)[0..];
2069 assert(@typeOf(slice) == []align(4) u8);
2069 assert(@TypeOf(slice) == []align(4) u8);
20702070}
20712071
20722072fn derp() align(@sizeOf(usize) * 2) i32 { return 1234; }
......@@ -2075,8 +2075,8 @@ fn noop4() align(4) void {}
20752075
20762076test "function alignment" {
20772077 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);
20802080 noop1();
20812081 noop4();
20822082}
......@@ -2162,8 +2162,8 @@ test "basic slices" {
21622162
21632163 // Using the address-of operator on a slice gives a pointer to a single
21642164 // 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);
21672167 assert(@ptrToInt(slice.ptr) == @ptrToInt(&slice[0]));
21682168
21692169 // Slices have array bounds checking. If you try to access something out
......@@ -2208,7 +2208,7 @@ test "slice pointer" {
22082208 slice[2] = 3;
22092209 assert(slice[2] == 3);
22102210 // The slice is mutable because we sliced a mutable pointer.
2211 assert(@typeOf(slice) == []u8);
2211 assert(@TypeOf(slice) == []u8);
22122212
22132213 // You can also slice a slice:
22142214 const slice2 = slice[2..3];
......@@ -3566,7 +3566,7 @@ test "for basics" {
35663566 // This is zero-indexed.
35673567 var sum2: i32 = 0;
35683568 for (items) |value, i| {
3569 assert(@typeOf(i) == usize);
3569 assert(@TypeOf(i) == usize);
35703570 sum2 += @intCast(i32, i);
35713571 }
35723572 assert(sum2 == 10);
......@@ -3909,7 +3909,7 @@ test "type of unreachable" {
39093909 // However this assertion will still fail because
39103910 // evaluating unreachable at compile-time is a compile error.
39113911
3912 assert(@typeOf(unreachable) == noreturn);
3912 assert(@TypeOf(unreachable) == noreturn);
39133913 }
39143914}
39153915 {#code_end#}
......@@ -4018,7 +4018,7 @@ test "function" {
40184018const assert = @import("std").debug.assert;
40194019
40204020comptime {
4021 assert(@typeOf(foo) == fn()void);
4021 assert(@TypeOf(foo) == fn()void);
40224022 assert(@sizeOf(fn()void) == @sizeOf(?fn()void));
40234023}
40244024
......@@ -4062,35 +4062,35 @@ test "pass struct to function" {
40624062 </p>
40634063 {#header_close#}
40644064 {#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.
40674067 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.
40694069 </p>
40704070 {#code_begin|test#}
40714071const assert = @import("std").debug.assert;
40724072
4073fn addFortyTwo(x: var) @typeOf(x) {
4073fn addFortyTwo(x: var) @TypeOf(x) {
40744074 return x + 42;
40754075}
40764076
40774077test "fn type inference" {
40784078 assert(addFortyTwo(1) == 43);
4079 assert(@typeOf(addFortyTwo(1)) == comptime_int);
4079 assert(@TypeOf(addFortyTwo(1)) == comptime_int);
40804080 var y: i64 = 2;
40814081 assert(addFortyTwo(y) == 44);
4082 assert(@typeOf(addFortyTwo(y)) == i64);
4082 assert(@TypeOf(addFortyTwo(y)) == i64);
40834083}
40844084 {#code_end#}
4085
4085
40864086 {#header_close#}
40874087 {#header_open|Function Reflection#}
40884088 {#code_begin|test#}
40894089const assert = @import("std").debug.assert;
40904090
40914091test "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);
40944094}
40954095 {#code_end#}
40964096 {#header_close#}
......@@ -4390,10 +4390,10 @@ test "error union" {
43904390 foo = error.SomeError;
43914391
43924392 // Use compile-time reflection to access the payload type of an error union:
4393 comptime assert(@typeOf(foo).Payload == i32);
4393 comptime assert(@TypeOf(foo).Payload == i32);
43944394
43954395 // 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);
43974397}
43984398 {#code_end#}
43994399 {#header_open|Merging Error Sets#}
......@@ -4770,7 +4770,7 @@ test "optional type" {
47704770 foo = 1234;
47714771
47724772 // 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);
47744774}
47754775 {#code_end#}
47764776 {#header_close#}
......@@ -5154,7 +5154,7 @@ test "peer resolve int widening" {
51545154 var b: i16 = 34;
51555155 var c = a + b;
51565156 assert(c == 46);
5157 assert(@typeOf(c) == i16);
5157 assert(@TypeOf(c) == i16);
51585158}
51595159
51605160test "peer resolve arrays of different size to const slice" {
......@@ -5949,7 +5949,7 @@ pub fn printf(self: *OutStream, arg0: i32, arg1: []const u8) !void {
59495949 </p>
59505950 {#code_begin|syntax#}
59515951pub fn printValue(self: *OutStream, value: var) !void {
5952 const T = @typeOf(value);
5952 const T = @TypeOf(value);
59535953 if (@isInteger(T)) {
59545954 return self.printInt(T, value);
59555955 } else if (@isFloat(T)) {
......@@ -6265,7 +6265,7 @@ test "async function suspend with block" {
62656265
62666266fn testSuspendBlock() void {
62676267 suspend {
6268 comptime assert(@typeOf(@frame()) == *@Frame(testSuspendBlock));
6268 comptime assert(@TypeOf(@frame()) == *@Frame(testSuspendBlock));
62696269 the_frame = @frame();
62706270 }
62716271 result = true;
......@@ -6332,7 +6332,7 @@ test "async and await" {
63326332
63336333fn amain() void {
63346334 var frame = async func();
6335 comptime assert(@typeOf(frame) == @Frame(func));
6335 comptime assert(@TypeOf(frame) == @Frame(func));
63366336
63376337 const ptr: anyframe->void = &frame;
63386338 const any_ptr: anyframe = ptr;
......@@ -6740,7 +6740,7 @@ async fn func(y: *i32) void {
67406740 Converts a value of one type to another type.
67416741 </p>
67426742 <p>
6743 Asserts that {#syntax#}@sizeOf(@typeOf(value)) == @sizeOf(DestType){#endsyntax#}.
6743 Asserts that {#syntax#}@sizeOf(@TypeOf(value)) == @sizeOf(DestType){#endsyntax#}.
67446744 </p>
67456745 <p>
67466746 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
70457045 <p>
70467046 {#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("builtin").AtomicOrder{#endsyntax#}.
70477047 </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>
70497049 {#see_also|Compile Variables|cmpxchgWeak#}
70507050 {#header_close#}
70517051 {#header_open|@cmpxchgWeak#}
......@@ -7073,7 +7073,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
70737073 <p>
70747074 {#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("builtin").AtomicOrder{#endsyntax#}.
70757075 </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>
70777077 {#see_also|Compile Variables|cmpxchgStrong#}
70787078 {#header_close#}
70797079
......@@ -8020,7 +8020,7 @@ test "@setRuntimeSafety" {
80208020 {#header_close#}
80218021
80228022 {#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>
80248024 <p>
80258025 Produces a vector of length {#syntax#}len{#endsyntax#} where each element is the value
80268026 {#syntax#}scalar{#endsyntax#}:
......@@ -8032,7 +8032,7 @@ const assert = std.debug.assert;
80328032test "vector @splat" {
80338033 const scalar: u32 = 5;
80348034 const result = @splat(4, scalar);
8035 comptime assert(@typeOf(result) == @Vector(4, u32));
8035 comptime assert(@TypeOf(result) == @Vector(4, u32));
80368036 assert(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
80378037}
80388038 {#code_end#}
......@@ -8250,8 +8250,8 @@ test "integer truncation" {
82508250 <li>{#link|Pointers#}</li>
82518251 <li>{#syntax#}comptime_int{#endsyntax#}</li>
82528252 <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>
82558255 </ul>
82568256 <p>
82578257 For these types it is a
......@@ -8516,20 +8516,20 @@ pub const TypeInfo = union(TypeId) {
85168516
85178517 {#header_close#}
85188518
8519 {#header_open|@typeOf#}
8520 <pre>{#syntax#}@typeOf(expression) type{#endsyntax#}</pre>
8519 {#header_open|@TypeOf#}
8520 <pre>{#syntax#}@TypeOf(expression) type{#endsyntax#}</pre>
85218521 <p>
85228522 This function returns a compile-time constant, which is the type of the
85238523 expression passed as an argument. The expression is evaluated.
85248524 </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>
85268526 {#code_begin|test#}
85278527const std = @import("std");
85288528const assert = std.debug.assert;
85298529
85308530test "no runtime side effects" {
85318531 var data: i32 = 0;
8532 const T = @typeOf(foo(i32, &data));
8532 const T = @TypeOf(foo(i32, &data));
85338533 comptime assert(T == i32);
85348534 assert(data == 0);
85358535}