| author | |
| committer | |
| log | 327fb798c3a2fb18588fc79b1f024cfdd166a4e9 |
| tree | 147b55e8e691d28f466f6f3cfe0fd24ac9f5ee98 |
| parent | 0b4461d97b5d315e71302f96076c54bbdffb7717 |
32 files changed, 297 insertions(+), 297 deletions(-)
test/cases/compile_errors/comptime_unreachable.zig created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | pub export fn entry() void { | ||
| 2 | comptime unreachable; | ||
| 3 | } | ||
| 4 | |||
| 5 | // error | ||
| 6 | // target=native | ||
| 7 | // backend=stage2 | ||
| 8 | // | ||
| 9 | // :2:14: error: reached unreachable code | ||
test/cases/compile_errors/constant_inside_comptime_function_has_compile_error.zig created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | const ContextAllocator = MemoryPool(usize); | ||
| 2 | |||
| 3 | pub fn MemoryPool(comptime T: type) type { | ||
| 4 | const free_list_t = @compileError("aoeu",); | ||
| 5 | _ = T; | ||
| 6 | |||
| 7 | return struct { | ||
| 8 | free_list: free_list_t, | ||
| 9 | }; | ||
| 10 | } | ||
| 11 | |||
| 12 | export fn entry() void { | ||
| 13 | var allocator: ContextAllocator = undefined; | ||
| 14 | _ = allocator; | ||
| 15 | } | ||
| 16 | |||
| 17 | // error | ||
| 18 | // target=native | ||
| 19 | // | ||
| 20 | // :4:5: error: unreachable code | ||
| 21 | // :4:25: note: control flow is diverted here | ||
test/cases/compile_errors/duplicate-unused_labels.zig created+31| ... | @@ -0,0 +1,31 @@ | ||
| 1 | comptime { | ||
| 2 | blk: { blk: while (false) {} } | ||
| 3 | } | ||
| 4 | comptime { | ||
| 5 | blk: while (false) { blk: for (@as([0]void, undefined)) |_| {} } | ||
| 6 | } | ||
| 7 | comptime { | ||
| 8 | blk: for (@as([0]void, undefined)) |_| { blk: {} } | ||
| 9 | } | ||
| 10 | comptime { | ||
| 11 | blk: {} | ||
| 12 | } | ||
| 13 | comptime { | ||
| 14 | blk: while(false) {} | ||
| 15 | } | ||
| 16 | comptime { | ||
| 17 | blk: for(@as([0]void, undefined)) |_| {} | ||
| 18 | } | ||
| 19 | |||
| 20 | // error | ||
| 21 | // target=native | ||
| 22 | // | ||
| 23 | // :2:12: error: redefinition of label 'blk' | ||
| 24 | // :2:5: note: previous definition here | ||
| 25 | // :5:26: error: redefinition of label 'blk' | ||
| 26 | // :5:5: note: previous definition here | ||
| 27 | // :8:46: error: redefinition of label 'blk' | ||
| 28 | // :8:5: note: previous definition here | ||
| 29 | // :11:5: error: unused block label | ||
| 30 | // :14:5: error: unused while loop label | ||
| 31 | // :17:5: error: unused for loop label | ||
test/cases/compile_errors/embed_outside_package.zig created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | export fn a() usize { | ||
| 2 | return @embedFile("/root/foo").len; | ||
| 3 | } | ||
| 4 | |||
| 5 | // error | ||
| 6 | // target=native | ||
| 7 | // | ||
| 8 | //:2:23: error: embed of file outside package path: '/root/foo' | ||
test/cases/compile_errors/import_outside_package.zig created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | export fn a() usize { | ||
| 2 | return @import("../../above.zig").len; | ||
| 3 | } | ||
| 4 | |||
| 5 | // error | ||
| 6 | // target=native | ||
| 7 | // | ||
| 8 | // :2:20: error: import of file outside package path: '../../above.zig' | ||
test/cases/compile_errors/out_of_bounds_index.zig created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | comptime { | ||
| 2 | var array = [_:0]u8{ 1, 2, 3, 4 }; | ||
| 3 | var src_slice: [:0]u8 = &array; | ||
| 4 | var slice = src_slice[2..6]; | ||
| 5 | _ = slice; | ||
| 6 | } | ||
| 7 | comptime { | ||
| 8 | var array = [_:0]u8{ 1, 2, 3, 4 }; | ||
| 9 | var slice = array[2..6]; | ||
| 10 | _ = slice; | ||
| 11 | } | ||
| 12 | comptime { | ||
| 13 | var array = [_]u8{ 1, 2, 3, 4 }; | ||
| 14 | var slice = array[2..5]; | ||
| 15 | _ = slice; | ||
| 16 | } | ||
| 17 | comptime { | ||
| 18 | var array = [_:0]u8{ 1, 2, 3, 4 }; | ||
| 19 | var slice = array[3..2]; | ||
| 20 | _ = slice; | ||
| 21 | } | ||
| 22 | |||
| 23 | // error | ||
| 24 | // target=native | ||
| 25 | // | ||
| 26 | // :4:30: error: end index 6 out of bounds for slice of length 4 +1 (sentinel) | ||
| 27 | // :9:26: error: end index 6 out of bounds for array of length 4 +1 (sentinel) | ||
| 28 | // :14:26: error: end index 5 out of bounds for array of length 4 | ||
| 29 | // :19:23: error: start index 3 is larger than end index 2 | ||
test/cases/compile_errors/reified_enum_field_value_overflow.zig created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | comptime { | ||
| 2 | const E = @Type(.{ .Enum = .{ | ||
| 3 | .layout = .Auto, | ||
| 4 | .tag_type = u1, | ||
| 5 | .fields = &.{ | ||
| 6 | .{ .name = "f0", .value = 0 }, | ||
| 7 | .{ .name = "f1", .value = 1 }, | ||
| 8 | .{ .name = "f2", .value = 2 }, | ||
| 9 | }, | ||
| 10 | .decls = &.{}, | ||
| 11 | .is_exhaustive = true, | ||
| 12 | } }); | ||
| 13 | _ = E; | ||
| 14 | } | ||
| 15 | |||
| 16 | // error | ||
| 17 | // target=native | ||
| 18 | // backend=stage2 | ||
| 19 | // | ||
| 20 | // :2:15: error: field 'f2' with enumeration value '2' is too large for backing int type 'u1' | ||
test/cases/compile_errors/slice_of_null_pointer.zig created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | comptime { | ||
| 2 | var x: [*c]u8 = null; | ||
| 3 | var runtime_len: usize = 0; | ||
| 4 | var y = x[0..runtime_len]; | ||
| 5 | _ = y; | ||
| 6 | } | ||
| 7 | |||
| 8 | // error | ||
| 9 | // target=native | ||
| 10 | // | ||
| 11 | // :4:14: error: slice of null pointer | ||
test/cases/compile_errors/stage2/comptime_unreachable.zig deleted-9| ... | @@ -1,9 +0,0 @@ | ||
| 1 | pub export fn entry() void { | ||
| 2 | comptime unreachable; | ||
| 3 | } | ||
| 4 | |||
| 5 | // error | ||
| 6 | // target=native | ||
| 7 | // backend=stage2 | ||
| 8 | // | ||
| 9 | // :2:14: error: reached unreachable code | ||
test/cases/compile_errors/stage2/constant_inside_comptime_function_has_compile_error.zig deleted-21| ... | @@ -1,21 +0,0 @@ | ||
| 1 | const ContextAllocator = MemoryPool(usize); | ||
| 2 | |||
| 3 | pub fn MemoryPool(comptime T: type) type { | ||
| 4 | const free_list_t = @compileError("aoeu",); | ||
| 5 | _ = T; | ||
| 6 | |||
| 7 | return struct { | ||
| 8 | free_list: free_list_t, | ||
| 9 | }; | ||
| 10 | } | ||
| 11 | |||
| 12 | export fn entry() void { | ||
| 13 | var allocator: ContextAllocator = undefined; | ||
| 14 | _ = allocator; | ||
| 15 | } | ||
| 16 | |||
| 17 | // error | ||
| 18 | // target=native | ||
| 19 | // | ||
| 20 | // :4:5: error: unreachable code | ||
| 21 | // :4:25: note: control flow is diverted here | ||
test/cases/compile_errors/stage2/duplicate-unused_labels.zig deleted-31| ... | @@ -1,31 +0,0 @@ | ||
| 1 | comptime { | ||
| 2 | blk: { blk: while (false) {} } | ||
| 3 | } | ||
| 4 | comptime { | ||
| 5 | blk: while (false) { blk: for (@as([0]void, undefined)) |_| {} } | ||
| 6 | } | ||
| 7 | comptime { | ||
| 8 | blk: for (@as([0]void, undefined)) |_| { blk: {} } | ||
| 9 | } | ||
| 10 | comptime { | ||
| 11 | blk: {} | ||
| 12 | } | ||
| 13 | comptime { | ||
| 14 | blk: while(false) {} | ||
| 15 | } | ||
| 16 | comptime { | ||
| 17 | blk: for(@as([0]void, undefined)) |_| {} | ||
| 18 | } | ||
| 19 | |||
| 20 | // error | ||
| 21 | // target=native | ||
| 22 | // | ||
| 23 | // :2:12: error: redefinition of label 'blk' | ||
| 24 | // :2:5: note: previous definition here | ||
| 25 | // :5:26: error: redefinition of label 'blk' | ||
| 26 | // :5:5: note: previous definition here | ||
| 27 | // :8:46: error: redefinition of label 'blk' | ||
| 28 | // :8:5: note: previous definition here | ||
| 29 | // :11:5: error: unused block label | ||
| 30 | // :14:5: error: unused while loop label | ||
| 31 | // :17:5: error: unused for loop label | ||
test/cases/compile_errors/stage2/embed_outside_package.zig deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | export fn a() usize { | ||
| 2 | return @embedFile("/root/foo").len; | ||
| 3 | } | ||
| 4 | |||
| 5 | // error | ||
| 6 | // target=native | ||
| 7 | // | ||
| 8 | //:2:23: error: embed of file outside package path: '/root/foo' | ||
test/cases/compile_errors/stage2/import_outside_package.zig deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | export fn a() usize { | ||
| 2 | return @import("../../above.zig").len; | ||
| 3 | } | ||
| 4 | |||
| 5 | // error | ||
| 6 | // target=native | ||
| 7 | // | ||
| 8 | // :2:20: error: import of file outside package path: '../../above.zig' | ||
test/cases/compile_errors/stage2/out_of_bounds_index.zig deleted-29| ... | @@ -1,29 +0,0 @@ | ||
| 1 | comptime { | ||
| 2 | var array = [_:0]u8{ 1, 2, 3, 4 }; | ||
| 3 | var src_slice: [:0]u8 = &array; | ||
| 4 | var slice = src_slice[2..6]; | ||
| 5 | _ = slice; | ||
| 6 | } | ||
| 7 | comptime { | ||
| 8 | var array = [_:0]u8{ 1, 2, 3, 4 }; | ||
| 9 | var slice = array[2..6]; | ||
| 10 | _ = slice; | ||
| 11 | } | ||
| 12 | comptime { | ||
| 13 | var array = [_]u8{ 1, 2, 3, 4 }; | ||
| 14 | var slice = array[2..5]; | ||
| 15 | _ = slice; | ||
| 16 | } | ||
| 17 | comptime { | ||
| 18 | var array = [_:0]u8{ 1, 2, 3, 4 }; | ||
| 19 | var slice = array[3..2]; | ||
| 20 | _ = slice; | ||
| 21 | } | ||
| 22 | |||
| 23 | // error | ||
| 24 | // target=native | ||
| 25 | // | ||
| 26 | // :4:30: error: end index 6 out of bounds for slice of length 4 +1 (sentinel) | ||
| 27 | // :9:26: error: end index 6 out of bounds for array of length 4 +1 (sentinel) | ||
| 28 | // :14:26: error: end index 5 out of bounds for array of length 4 | ||
| 29 | // :19:23: error: start index 3 is larger than end index 2 | ||
test/cases/compile_errors/stage2/reified_enum_field_value_overflow.zig deleted-20| ... | @@ -1,20 +0,0 @@ | ||
| 1 | comptime { | ||
| 2 | const E = @Type(.{ .Enum = .{ | ||
| 3 | .layout = .Auto, | ||
| 4 | .tag_type = u1, | ||
| 5 | .fields = &.{ | ||
| 6 | .{ .name = "f0", .value = 0 }, | ||
| 7 | .{ .name = "f1", .value = 1 }, | ||
| 8 | .{ .name = "f2", .value = 2 }, | ||
| 9 | }, | ||
| 10 | .decls = &.{}, | ||
| 11 | .is_exhaustive = true, | ||
| 12 | } }); | ||
| 13 | _ = E; | ||
| 14 | } | ||
| 15 | |||
| 16 | // error | ||
| 17 | // target=native | ||
| 18 | // backend=stage2 | ||
| 19 | // | ||
| 20 | // :2:15: error: field 'f2' with enumeration value '2' is too large for backing int type 'u1' | ||
test/cases/compile_errors/stage2/slice_of_null_pointer.zig deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | comptime { | ||
| 2 | var x: [*c]u8 = null; | ||
| 3 | var runtime_len: usize = 0; | ||
| 4 | var y = x[0..runtime_len]; | ||
| 5 | _ = y; | ||
| 6 | } | ||
| 7 | |||
| 8 | // error | ||
| 9 | // target=native | ||
| 10 | // | ||
| 11 | // :4:14: error: slice of null pointer | ||
test/cases/compile_errors/stage2/struct_duplicate_field_name.zig deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | const S = struct { | ||
| 2 | foo: u32, | ||
| 3 | foo: u32, | ||
| 4 | }; | ||
| 5 | |||
| 6 | export fn entry() void { | ||
| 7 | const s: S = .{ .foo = 100 }; | ||
| 8 | _ = s; | ||
| 9 | } | ||
| 10 | |||
| 11 | // error | ||
| 12 | // target=native | ||
| 13 | // | ||
| 14 | // :3:5: error: duplicate struct field: 'foo' | ||
| 15 | // :2:5: note: other field here | ||
| 16 | // :1:11: note: struct declared here | ||
test/cases/compile_errors/stage2/tuple_ptr_to_mut_slice.zig deleted-32| ... | @@ -1,32 +0,0 @@ | ||
| 1 | export fn entry1() void { | ||
| 2 | var a = .{ 1, 2, 3 }; | ||
| 3 | _ = @as([]u8, &a); | ||
| 4 | } | ||
| 5 | export fn entry2() void { | ||
| 6 | var a = .{ @as(u8, 1), @as(u8, 2), @as(u8, 3) }; | ||
| 7 | _ = @as([]u8, &a); | ||
| 8 | } | ||
| 9 | |||
| 10 | // runtime values | ||
| 11 | var vals = [_]u7{ 4, 5, 6 }; | ||
| 12 | export fn entry3() void { | ||
| 13 | var a = .{ vals[0], vals[1], vals[2] }; | ||
| 14 | _ = @as([]u8, &a); | ||
| 15 | } | ||
| 16 | export fn entry4() void { | ||
| 17 | var a = .{ @as(u8, vals[0]), @as(u8, vals[1]), @as(u8, vals[2]) }; | ||
| 18 | _ = @as([]u8, &a); | ||
| 19 | } | ||
| 20 | |||
| 21 | // error | ||
| 22 | // backend=stage2 | ||
| 23 | // target=native | ||
| 24 | // | ||
| 25 | // :3:19: error: cannot cast pointer to tuple to '[]u8' | ||
| 26 | // :3:19: note: pointers to tuples can only coerce to constant pointers | ||
| 27 | // :7:19: error: cannot cast pointer to tuple to '[]u8' | ||
| 28 | // :7:19: note: pointers to tuples can only coerce to constant pointers | ||
| 29 | // :14:19: error: cannot cast pointer to tuple to '[]u8' | ||
| 30 | // :14:19: note: pointers to tuples can only coerce to constant pointers | ||
| 31 | // :18:19: error: cannot cast pointer to tuple to '[]u8' | ||
| 32 | // :18:19: note: pointers to tuples can only coerce to constant pointers | ||
test/cases/compile_errors/stage2/union_access_of_inactive_field.zig deleted-15| ... | @@ -1,15 +0,0 @@ | ||
| 1 | const U = union { | ||
| 2 | a: void, | ||
| 3 | b: u64, | ||
| 4 | }; | ||
| 5 | comptime { | ||
| 6 | var u: U = .{ .a = {} }; | ||
| 7 | const v = u.b; | ||
| 8 | _ = v; | ||
| 9 | } | ||
| 10 | |||
| 11 | // error | ||
| 12 | // target=native | ||
| 13 | // | ||
| 14 | // :7:16: error: access of union field 'b' while field 'a' is active | ||
| 15 | // :1:11: note: union declared here | ||
test/cases/compile_errors/stage2/union_duplicate_enum_field.zig deleted-17| ... | @@ -1,17 +0,0 @@ | ||
| 1 | const E = enum { a, b }; | ||
| 2 | const U = union(E) { | ||
| 3 | a: u32, | ||
| 4 | a: u32, | ||
| 5 | }; | ||
| 6 | |||
| 7 | export fn foo() void { | ||
| 8 | var u: U = .{ .a = 123 }; | ||
| 9 | _ = u; | ||
| 10 | } | ||
| 11 | |||
| 12 | // error | ||
| 13 | // target=native | ||
| 14 | // | ||
| 15 | // :4:5: error: duplicate union field: 'a' | ||
| 16 | // :3:5: note: other field here | ||
| 17 | // :2:11: note: union declared here | ||
test/cases/compile_errors/stage2/union_duplicate_field_definition.zig deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | const U = union { | ||
| 2 | foo: u32, | ||
| 3 | foo: u32, | ||
| 4 | }; | ||
| 5 | |||
| 6 | export fn entry() void { | ||
| 7 | const u: U = .{ .foo = 100 }; | ||
| 8 | _ = u; | ||
| 9 | } | ||
| 10 | |||
| 11 | // error | ||
| 12 | // target=native | ||
| 13 | // | ||
| 14 | // :3:5: error: duplicate union field: 'foo' | ||
| 15 | // :2:5: note: other field here | ||
| 16 | // :1:11: note: union declared here | ||
test/cases/compile_errors/stage2/union_enum_field_missing.zig deleted-21| ... | @@ -1,21 +0,0 @@ | ||
| 1 | const E = enum { | ||
| 2 | a, | ||
| 3 | b, | ||
| 4 | c, | ||
| 5 | }; | ||
| 6 | |||
| 7 | const U = union(E) { | ||
| 8 | a: i32, | ||
| 9 | b: f64, | ||
| 10 | }; | ||
| 11 | |||
| 12 | export fn entry() usize { | ||
| 13 | return @sizeOf(U); | ||
| 14 | } | ||
| 15 | |||
| 16 | // error | ||
| 17 | // target=native | ||
| 18 | // | ||
| 19 | // :7:11: error: enum field(s) missing in union | ||
| 20 | // :4:5: note: field 'c' missing, declared here | ||
| 21 | // :1:11: note: enum declared here | ||
test/cases/compile_errors/stage2/union_extra_field.zig deleted-20| ... | @@ -1,20 +0,0 @@ | ||
| 1 | const E = enum { | ||
| 2 | a, | ||
| 3 | b, | ||
| 4 | c, | ||
| 5 | }; | ||
| 6 | const U = union(E) { | ||
| 7 | a: i32, | ||
| 8 | b: f64, | ||
| 9 | c: f64, | ||
| 10 | d: f64, | ||
| 11 | }; | ||
| 12 | export fn entry() usize { | ||
| 13 | return @sizeOf(U); | ||
| 14 | } | ||
| 15 | |||
| 16 | // error | ||
| 17 | // target=native | ||
| 18 | // | ||
| 19 | // :10:5: error: no field named 'd' in enum 'tmp.E' | ||
| 20 | // :1:11: note: enum declared here | ||
test/cases/compile_errors/stage2/union_runtime_coercion_from_enum.zig deleted-23| ... | @@ -1,23 +0,0 @@ | ||
| 1 | const E = enum { | ||
| 2 | a, | ||
| 3 | b, | ||
| 4 | }; | ||
| 5 | const U = union(E) { | ||
| 6 | a: u32, | ||
| 7 | b: u64, | ||
| 8 | }; | ||
| 9 | fn foo() E { | ||
| 10 | return E.b; | ||
| 11 | } | ||
| 12 | export fn doTheTest() u64 { | ||
| 13 | var u: U = foo(); | ||
| 14 | return u.b; | ||
| 15 | } | ||
| 16 | |||
| 17 | // error | ||
| 18 | // target=native | ||
| 19 | // | ||
| 20 | // :13:19: error: runtime coercion from enum 'tmp.E' to union 'tmp.U' which has non-void fields | ||
| 21 | // :6:5: note: field 'a' has type 'u32' | ||
| 22 | // :7:5: note: field 'b' has type 'u64' | ||
| 23 | // :5:11: note: union declared here | ||
test/cases/compile_errors/struct_duplicate_field_name.zig created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | const S = struct { | ||
| 2 | foo: u32, | ||
| 3 | foo: u32, | ||
| 4 | }; | ||
| 5 | |||
| 6 | export fn entry() void { | ||
| 7 | const s: S = .{ .foo = 100 }; | ||
| 8 | _ = s; | ||
| 9 | } | ||
| 10 | |||
| 11 | // error | ||
| 12 | // target=native | ||
| 13 | // | ||
| 14 | // :3:5: error: duplicate struct field: 'foo' | ||
| 15 | // :2:5: note: other field here | ||
| 16 | // :1:11: note: struct declared here | ||
test/cases/compile_errors/tuple_ptr_to_mut_slice.zig created+32| ... | @@ -0,0 +1,32 @@ | ||
| 1 | export fn entry1() void { | ||
| 2 | var a = .{ 1, 2, 3 }; | ||
| 3 | _ = @as([]u8, &a); | ||
| 4 | } | ||
| 5 | export fn entry2() void { | ||
| 6 | var a = .{ @as(u8, 1), @as(u8, 2), @as(u8, 3) }; | ||
| 7 | _ = @as([]u8, &a); | ||
| 8 | } | ||
| 9 | |||
| 10 | // runtime values | ||
| 11 | var vals = [_]u7{ 4, 5, 6 }; | ||
| 12 | export fn entry3() void { | ||
| 13 | var a = .{ vals[0], vals[1], vals[2] }; | ||
| 14 | _ = @as([]u8, &a); | ||
| 15 | } | ||
| 16 | export fn entry4() void { | ||
| 17 | var a = .{ @as(u8, vals[0]), @as(u8, vals[1]), @as(u8, vals[2]) }; | ||
| 18 | _ = @as([]u8, &a); | ||
| 19 | } | ||
| 20 | |||
| 21 | // error | ||
| 22 | // backend=stage2 | ||
| 23 | // target=native | ||
| 24 | // | ||
| 25 | // :3:19: error: cannot cast pointer to tuple to '[]u8' | ||
| 26 | // :3:19: note: pointers to tuples can only coerce to constant pointers | ||
| 27 | // :7:19: error: cannot cast pointer to tuple to '[]u8' | ||
| 28 | // :7:19: note: pointers to tuples can only coerce to constant pointers | ||
| 29 | // :14:19: error: cannot cast pointer to tuple to '[]u8' | ||
| 30 | // :14:19: note: pointers to tuples can only coerce to constant pointers | ||
| 31 | // :18:19: error: cannot cast pointer to tuple to '[]u8' | ||
| 32 | // :18:19: note: pointers to tuples can only coerce to constant pointers | ||
test/cases/compile_errors/union_access_of_inactive_field.zig created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | const U = union { | ||
| 2 | a: void, | ||
| 3 | b: u64, | ||
| 4 | }; | ||
| 5 | comptime { | ||
| 6 | var u: U = .{ .a = {} }; | ||
| 7 | const v = u.b; | ||
| 8 | _ = v; | ||
| 9 | } | ||
| 10 | |||
| 11 | // error | ||
| 12 | // target=native | ||
| 13 | // | ||
| 14 | // :7:16: error: access of union field 'b' while field 'a' is active | ||
| 15 | // :1:11: note: union declared here | ||
test/cases/compile_errors/union_duplicate_enum_field.zig created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | const E = enum { a, b }; | ||
| 2 | const U = union(E) { | ||
| 3 | a: u32, | ||
| 4 | a: u32, | ||
| 5 | }; | ||
| 6 | |||
| 7 | export fn foo() void { | ||
| 8 | var u: U = .{ .a = 123 }; | ||
| 9 | _ = u; | ||
| 10 | } | ||
| 11 | |||
| 12 | // error | ||
| 13 | // target=native | ||
| 14 | // | ||
| 15 | // :4:5: error: duplicate union field: 'a' | ||
| 16 | // :3:5: note: other field here | ||
| 17 | // :2:11: note: union declared here | ||
test/cases/compile_errors/union_duplicate_field_definition.zig created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | const U = union { | ||
| 2 | foo: u32, | ||
| 3 | foo: u32, | ||
| 4 | }; | ||
| 5 | |||
| 6 | export fn entry() void { | ||
| 7 | const u: U = .{ .foo = 100 }; | ||
| 8 | _ = u; | ||
| 9 | } | ||
| 10 | |||
| 11 | // error | ||
| 12 | // target=native | ||
| 13 | // | ||
| 14 | // :3:5: error: duplicate union field: 'foo' | ||
| 15 | // :2:5: note: other field here | ||
| 16 | // :1:11: note: union declared here | ||
test/cases/compile_errors/union_enum_field_missing.zig created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | const E = enum { | ||
| 2 | a, | ||
| 3 | b, | ||
| 4 | c, | ||
| 5 | }; | ||
| 6 | |||
| 7 | const U = union(E) { | ||
| 8 | a: i32, | ||
| 9 | b: f64, | ||
| 10 | }; | ||
| 11 | |||
| 12 | export fn entry() usize { | ||
| 13 | return @sizeOf(U); | ||
| 14 | } | ||
| 15 | |||
| 16 | // error | ||
| 17 | // target=native | ||
| 18 | // | ||
| 19 | // :7:11: error: enum field(s) missing in union | ||
| 20 | // :4:5: note: field 'c' missing, declared here | ||
| 21 | // :1:11: note: enum declared here | ||
test/cases/compile_errors/union_extra_field.zig created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | const E = enum { | ||
| 2 | a, | ||
| 3 | b, | ||
| 4 | c, | ||
| 5 | }; | ||
| 6 | const U = union(E) { | ||
| 7 | a: i32, | ||
| 8 | b: f64, | ||
| 9 | c: f64, | ||
| 10 | d: f64, | ||
| 11 | }; | ||
| 12 | export fn entry() usize { | ||
| 13 | return @sizeOf(U); | ||
| 14 | } | ||
| 15 | |||
| 16 | // error | ||
| 17 | // target=native | ||
| 18 | // | ||
| 19 | // :10:5: error: no field named 'd' in enum 'tmp.E' | ||
| 20 | // :1:11: note: enum declared here | ||
test/cases/compile_errors/union_runtime_coercion_from_enum.zig created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | const E = enum { | ||
| 2 | a, | ||
| 3 | b, | ||
| 4 | }; | ||
| 5 | const U = union(E) { | ||
| 6 | a: u32, | ||
| 7 | b: u64, | ||
| 8 | }; | ||
| 9 | fn foo() E { | ||
| 10 | return E.b; | ||
| 11 | } | ||
| 12 | export fn doTheTest() u64 { | ||
| 13 | var u: U = foo(); | ||
| 14 | return u.b; | ||
| 15 | } | ||
| 16 | |||
| 17 | // error | ||
| 18 | // target=native | ||
| 19 | // | ||
| 20 | // :13:19: error: runtime coercion from enum 'tmp.E' to union 'tmp.U' which has non-void fields | ||
| 21 | // :6:5: note: field 'a' has type 'u32' | ||
| 22 | // :7:5: note: field 'b' has type 'u64' | ||
| 23 | // :5:11: note: union declared here | ||