From 6b2f4fd20d3c85e5db592f76dea8e56da54e9211 Mon Sep 17 00:00:00 2001 From: Vexu Date: Fri, 4 Sep 2020 21:41:34 +0300 Subject: langref: atomic ops are allowed on pointers Closes #6217 --- test/compile_errors.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/compile_errors.zig') diff --git a/test/compile_errors.zig b/test/compile_errors.zig index f6e00e1dbb..e4a00e6421 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -899,7 +899,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ _ = @cmpxchgWeak(f32, &x, 1, 2, .SeqCst, .SeqCst); \\} , &[_][]const u8{ - "tmp.zig:3:22: error: expected integer, enum or pointer type, found 'f32'", + "tmp.zig:3:22: error: expected bool, integer, enum or pointer type, found 'f32'", }); cases.add("atomicrmw with float op not .Xchg, .Add or .Sub", -- cgit v1.2.3 From 09c861b829480be525a787e54117c108705256e6 Mon Sep 17 00:00:00 2001 From: Vexu Date: Fri, 4 Sep 2020 22:49:14 +0300 Subject: update rest of tests --- doc/langref.html.in | 20 ++++++++++---------- lib/std/pdb.zig | 2 +- lib/std/start.zig | 2 +- test/compile_errors.zig | 23 +++++++---------------- 4 files changed, 19 insertions(+), 28 deletions(-) (limited to 'test/compile_errors.zig') diff --git a/doc/langref.html.in b/doc/langref.html.in index b9b8f71c7a..b01b543a40 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -2156,7 +2156,7 @@ test "pointer casting" { test "pointer child type" { // pointer types have a `child` field which tells you the type they point to. - assert((*u32).Child == u32); + assert(@typeInfo(*u32).Pointer.child == u32); } {#code_end#} {#header_open|Alignment#} @@ -2184,7 +2184,7 @@ test "variable alignment" { assert(@TypeOf(&x) == *i32); assert(*i32 == *align(align_of_i32) i32); if (std.Target.current.cpu.arch == .x86_64) { - assert((*i32).alignment == 4); + assert(@typeInfo(*i32).Pointer.alignment == 4); } } {#code_end#} @@ -2202,7 +2202,7 @@ const assert = @import("std").debug.assert; var foo: u8 align(4) = 100; test "global variable alignment" { - assert(@TypeOf(&foo).alignment == 4); + assert(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4); assert(@TypeOf(&foo) == *align(4) u8); const as_pointer_to_array: *[1]u8 = &foo; const as_slice: []u8 = as_pointer_to_array; @@ -4310,8 +4310,8 @@ test "fn type inference" { const assert = @import("std").debug.assert; test "fn reflection" { - assert(@TypeOf(assert).ReturnType == void); - assert(@TypeOf(assert).is_var_args == false); + assert(@typeInfo(@TypeOf(assert)).Fn.return_type.? == void); + assert(@typeInfo(@TypeOf(assert)).Fn.is_var_args == false); } {#code_end#} {#header_close#} @@ -4611,10 +4611,10 @@ test "error union" { foo = error.SomeError; // Use compile-time reflection to access the payload type of an error union: - comptime assert(@TypeOf(foo).Payload == i32); + comptime assert(@typeInfo(@TypeOf(foo)).ErrorUnion.payload == i32); // Use compile-time reflection to access the error set type of an error union: - comptime assert(@TypeOf(foo).ErrorSet == anyerror); + comptime assert(@typeInfo(@TypeOf(foo)).ErrorUnion.error_set == anyerror); } {#code_end#} {#header_open|Merging Error Sets#} @@ -4991,7 +4991,7 @@ test "optional type" { foo = 1234; // Use compile-time reflection to access the child type of the optional: - comptime assert(@TypeOf(foo).Child == i32); + comptime assert(@typeInfo(@TypeOf(foo)).Optional.child == i32); } {#code_end#} {#header_close#} @@ -7211,7 +7211,7 @@ fn cmpxchgStrongButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_v {#syntax#}T{#endsyntax#} must be a {#syntax#}bool{#endsyntax#}, a float, an integer or an enum.

-

{#syntax#}@TypeOf(ptr).alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}

+

{#syntax#}@typeInfo(@TypeOf(ptr)).Pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}

{#see_also|Compile Variables|cmpxchgWeak#} {#header_close#} {#header_open|@cmpxchgWeak#} @@ -7240,7 +7240,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val {#syntax#}T{#endsyntax#} must be a {#syntax#}bool{#endsyntax#}, a float, an integer or an enum.

-

{#syntax#}@TypeOf(ptr).alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}

+

{#syntax#}@typeInfo(@TypeOf(ptr)).Pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}

{#see_also|Compile Variables|cmpxchgStrong#} {#header_close#} diff --git a/lib/std/pdb.zig b/lib/std/pdb.zig index e8c61f859d..91e22307d8 100644 --- a/lib/std/pdb.zig +++ b/lib/std/pdb.zig @@ -636,7 +636,7 @@ const MsfStream = struct { blocks: []u32 = undefined, block_size: u32 = undefined, - pub const Error = @TypeOf(read).ReturnType.ErrorSet; + pub const Error = @typeInfo(@typeInfo(@TypeOf(read)).Fn.return_type.?).ErrorUnion.error_set; fn init(block_size: u32, file: File, blocks: []u32) MsfStream { const stream = MsfStream{ diff --git a/lib/std/start.zig b/lib/std/start.zig index e04b2a3320..3eb02ba65e 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -67,7 +67,7 @@ fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv uefi.handle = handle; uefi.system_table = system_table; - switch (@TypeOf(root.main).ReturnType) { + switch (@typeInfo(@TypeOf(read)).Fn.return_type.?) { noreturn => { root.main(); }, diff --git a/test/compile_errors.zig b/test/compile_errors.zig index f6e00e1dbb..d6a0b34911 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -176,11 +176,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { , &[_][]const u8{ "tmp.zig:2:17: error: expected type 'u32', found 'error{Ohno}'", "tmp.zig:1:17: note: function cannot return an error", - "tmp.zig:8:5: error: expected type 'void', found '@TypeOf(bar).ReturnType.ErrorSet'", + "tmp.zig:8:5: error: expected type 'void', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set'", "tmp.zig:7:17: note: function cannot return an error", - "tmp.zig:11:15: error: expected type 'u32', found '@TypeOf(bar).ReturnType.ErrorSet!u32'", + "tmp.zig:11:15: error: expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set!u32'", "tmp.zig:10:17: note: function cannot return an error", - "tmp.zig:15:14: error: expected type 'u32', found '@TypeOf(bar).ReturnType.ErrorSet!u32'", + "tmp.zig:15:14: error: expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set!u32'", "tmp.zig:14:5: note: cannot store an error in type 'u32'", }); @@ -1224,7 +1224,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ }; \\} , &[_][]const u8{ - "tmp.zig:11:25: error: expected type 'u32', found '@TypeOf(get_uval).ReturnType.ErrorSet!u32'", + "tmp.zig:11:25: error: expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(get_uval)).Fn.return_type.?).ErrorUnion.error_set!u32'", }); cases.add("assigning to struct or union fields that are not optionals with a function that returns an optional", @@ -1929,7 +1929,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ const info = @TypeOf(slice).unknown; \\} , &[_][]const u8{ - "tmp.zig:3:32: error: type '[]i32' does not support field access", + "tmp.zig:3:32: error: type 'type' does not support field access", }); cases.add("peer cast then implicit cast const pointer to mutable C pointer", @@ -3542,7 +3542,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ } \\} , &[_][]const u8{ - "tmp.zig:5:14: error: duplicate switch value: '@TypeOf(foo).ReturnType.ErrorSet.Foo'", + "tmp.zig:5:14: error: duplicate switch value: '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set.Foo'", "tmp.zig:3:14: note: other value is here", }); @@ -3674,7 +3674,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ try foo(); \\} , &[_][]const u8{ - "tmp.zig:5:5: error: cannot resolve inferred error set '@TypeOf(foo).ReturnType.ErrorSet': function 'foo' not fully analyzed yet", + "tmp.zig:5:5: error: cannot resolve inferred error set '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set': function 'foo' not fully analyzed yet", }); cases.add("implicit cast of error set not a subset", @@ -7206,15 +7206,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set", }); - cases.add("getting return type of generic function", - \\fn generic(a: anytype) void {} - \\comptime { - \\ _ = @TypeOf(generic).ReturnType; - \\} - , &[_][]const u8{ - "tmp.zig:3:25: error: ReturnType has not been resolved because 'fn(anytype) anytype' is generic", - }); - cases.add("unsupported modifier at start of asm output constraint", \\export fn foo() void { \\ var bar: u32 = 3; -- cgit v1.2.3