authorgravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2022-12-15 21:54:03+01:00
committergravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2022-12-21 23:34:29+01:00
loga429f72ae80d748a860a7f812510399cfe80ed97
treedec8ecc056a5f6a77a9ffd9db4209e9a1144df73
parent5ecc2b99afca8c9a9405d296a1f11d26a3ff2823

cases: more test coverage

Closes #11986 Closes #11850 Closes #12159

3 files changed, 25 insertions(+), 4 deletions(-)

test/cases/compile_errors/implicit_cast_const_array_to_mutable_slice.zig+7
...@@ -13,6 +13,11 @@ export fn entry2() void {...@@ -13,6 +13,11 @@ export fn entry2() void {
13 const many: [*]u8 = str;13 const many: [*]u8 = str;
14 _ = many;14 _ = many;
15}15}
16export fn entry3() void {
17 const lang: []const u8 = "lang";
18 const targets: [1][]const u8 = [_][]u8{lang};
19 _ = targets;
20}
1621
17// error22// error
18// backend=stage223// backend=stage2
...@@ -24,3 +29,5 @@ export fn entry2() void {...@@ -24,3 +29,5 @@ export fn entry2() void {
24// :8:27: note: cast discards const qualifier29// :8:27: note: cast discards const qualifier
25// :13:25: error: expected type '[*]u8', found '*const [0:0]u8'30// :13:25: error: expected type '[*]u8', found '*const [0:0]u8'
26// :13:25: note: cast discards const qualifier31// :13:25: note: cast discards const qualifier
32// :18:44: error: expected type '[]u8', found '[]const u8'
33// :18:44: note: cast discards const qualifier
test/cases/compile_errors/invalid_store_to_comptime_field.zig+6
...@@ -61,6 +61,11 @@ pub export fn entry6() void {...@@ -61,6 +61,11 @@ pub export fn entry6() void {
61 };61 };
62 _ = State.init(false);62 _ = State.init(false);
63}63}
64pub export fn entry7() void {
65 const list1 = .{ "sss", 1, 2, 3 };
66 const list2 = @TypeOf(list1){ .@"0" = "xxx", .@"1" = 4, .@"2" = 5, .@"3" = 6 };
67 _ = list2;
68}
6469
65// error70// error
66// target=native71// target=native
...@@ -73,4 +78,5 @@ pub export fn entry6() void {...@@ -73,4 +78,5 @@ pub export fn entry6() void {
73// :25:29: note: default value set here78// :25:29: note: default value set here
74// :41:16: error: value stored in comptime field does not match the default value of the field79// :41:16: error: value stored in comptime field does not match the default value of the field
75// :45:12: error: value stored in comptime field does not match the default value of the field80// :45:12: error: value stored in comptime field does not match the default value of the field
81// :66:43: error: value stored in comptime field does not match the default value of the field
76// :59:35: error: value stored in comptime field does not match the default value of the field82// :59:35: error: value stored in comptime field does not match the default value of the field
test/cases/compile_errors/invalid_struct_field.zig+12-4
...@@ -1,15 +1,22 @@...@@ -1,15 +1,22 @@
1const A = struct { x : i32, };1const A = struct { x: i32 };
2export fn f() void {2export fn f() void {
3 var a : A = undefined;3 var a: A = undefined;
4 a.foo = 1;4 a.foo = 1;
5 const y = a.bar;5 const y = a.bar;
6 _ = y;6 _ = y;
7}7}
8export fn g() void {8export fn g() void {
9 var a : A = undefined;9 var a: A = undefined;
10 const y = a.bar;10 const y = a.bar;
11 _ = y;11 _ = y;
12}12}
13export fn e() void {
14 const B = struct {
15 fn f() void {}
16 };
17 const b: B = undefined;
18 @import("std").debug.print("{}{}", .{ b.f, b.f });
19}
1320
14// error21// error
15// backend=stage222// backend=stage2
...@@ -18,4 +25,5 @@ export fn g() void {...@@ -18,4 +25,5 @@ export fn g() void {
18// :4:7: error: no field named 'foo' in struct 'tmp.A'25// :4:7: error: no field named 'foo' in struct 'tmp.A'
19// :1:11: note: struct declared here26// :1:11: note: struct declared here
20// :10:17: error: no field named 'bar' in struct 'tmp.A'27// :10:17: error: no field named 'bar' in struct 'tmp.A'
2128// :18:45: error: no field named 'f' in struct 'tmp.e.B'
29// :14:15: note: struct declared here