authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-28 18:35:37+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-29 23:43:52+01:00
log605f2a0978c3ae262e224ff01d163d412a64c284
tree5dbe00111ee2269e7dc345d30492d1197bc383bd
parentc62487da76b08a0dfb69fbf76501250ca065c140
signaturelock-open Commit is signed but in an unrecognized format.

cases: update for new error wording, add coverage for field/decl name conflict


19 files changed, 68 insertions(+), 49 deletions(-)

test/cases/compile_errors/colliding_invalid_top_level_functions.zig+3-4
......@@ -5,10 +5,9 @@ export fn entry() usize {
55}
66
77// error
8// backend=stage2
9// target=native
108//
11// :2:1: error: redeclaration of 'func'
12// :1:1: note: other declaration here
9// :1:4: error: duplicate struct member name 'func'
10// :2:4: note: duplicate name here
11// :1:1: note: struct declared here
1312// :1:11: error: use of undeclared identifier 'bogus'
1413// :2:11: error: use of undeclared identifier 'bogus'
test/cases/compile_errors/decl_shadows_local.zig+3-2
......@@ -2,6 +2,7 @@ fn foo(a: usize) void {
22 struct {
33 const a = 1;
44 };
5 _ = a;
56}
67fn bar(a: usize) void {
78 struct {
......@@ -18,5 +19,5 @@ fn bar(a: usize) void {
1819//
1920// :3:15: error: declaration 'a' shadows function parameter from outer scope
2021// :1:8: note: previous declaration here
21// :9:19: error: declaration 'a' shadows function parameter from outer scope
22// :6:8: note: previous declaration here
22// :10:19: error: declaration 'a' shadows function parameter from outer scope
23// :7:8: note: previous declaration here
test/cases/compile_errors/duplicate_enum_field.zig+2-2
......@@ -12,6 +12,6 @@ export fn entry() void {
1212// backend=stage2
1313// target=native
1414//
15// :2:5: error: duplicate enum field name
16// :3:5: note: duplicate field here
15// :2:5: error: duplicate enum member name 'Bar'
16// :3:5: note: duplicate name here
1717// :1:13: note: enum declared here
test/cases/compile_errors/duplicate_struct_field.zig+5-5
......@@ -24,10 +24,10 @@ export fn b() void {
2424// backend=stage2
2525// target=native
2626//
27// :2:5: error: duplicate struct field name
28// :3:5: note: duplicate field here
27// :2:5: error: duplicate struct member name 'Bar'
28// :3:5: note: duplicate name here
2929// :1:13: note: struct declared here
30// :7:5: error: duplicate struct field name
31// :9:5: note: duplicate field here
32// :10:5: note: duplicate field here
30// :7:5: error: duplicate struct member name 'a'
31// :9:5: note: duplicate name here
32// :10:5: note: duplicate name here
3333// :6:11: note: struct declared here
test/cases/compile_errors/duplicate_union_field.zig+2-4
......@@ -8,9 +8,7 @@ export fn entry() void {
88}
99
1010// error
11// backend=stage2
12// target=native
1311//
14// :2:5: error: duplicate union field name
15// :3:5: note: duplicate field here
12// :2:5: error: duplicate union member name 'Bar'
13// :3:5: note: duplicate name here
1614// :1:13: note: union declared here
test/cases/compile_errors/error_in_struct_initializer_doesnt_crash_the_compiler.zig+2-4
......@@ -8,9 +8,7 @@ pub export fn entry() void {
88}
99
1010// error
11// backend=stage2
12// target=native
1311//
14// :3:9: error: duplicate struct field name
15// :4:9: note: duplicate field here
12// :3:9: error: duplicate struct member name 'e'
13// :4:9: note: duplicate name here
1614// :2:22: note: struct declared here
test/cases/compile_errors/field_decl_name_conflict.zig created+18
......@@ -0,0 +1,18 @@
1foo: u32,
2bar: u32,
3qux: u32,
4
5const foo = 123;
6
7var bar: u8 = undefined;
8fn bar() void {}
9
10// error
11//
12// :1:1: error: duplicate struct member name 'foo'
13// :5:7: note: duplicate name here
14// :1:1: note: struct declared here
15// :2:1: error: duplicate struct member name 'bar'
16// :7:5: note: duplicate name here
17// :8:4: note: duplicate name here
18// :1:1: note: struct declared here
test/cases/compile_errors/invalid_duplicate_test_decl_name.zig+3-2
......@@ -6,5 +6,6 @@ test "thingy" {}
66// target=native
77// is_test=true
88//
9// :2:1: error: duplicate test name 'thingy'
10// :1:1: note: other test here
9// :1:6: error: duplicate test name 'thingy'
10// :2:6: note: duplicate test here
11// :1:1: note: struct declared here
test/cases/compile_errors/invalid_store_to_comptime_field.zig+4-4
......@@ -25,21 +25,21 @@ pub export fn entry3() void {
2525 const U = struct {
2626 comptime foo: u32 = 1,
2727 bar: u32,
28 fn foo(x: @This()) void {
28 fn qux(x: @This()) void {
2929 _ = x;
3030 }
3131 };
32 _ = U.foo(U{ .foo = 2, .bar = 2 });
32 _ = U.qux(U{ .foo = 2, .bar = 2 });
3333}
3434pub export fn entry4() void {
3535 const U = struct {
3636 comptime foo: u32 = 1,
3737 bar: u32,
38 fn foo(x: @This()) void {
38 fn qux(x: @This()) void {
3939 _ = x;
4040 }
4141 };
42 _ = U.foo(.{ .foo = 2, .bar = 2 });
42 _ = U.qux(.{ .foo = 2, .bar = 2 });
4343}
4444pub export fn entry5() void {
4545 comptime var y = .{ 1, 2 };
test/cases/compile_errors/multiple_function_definitions.zig+3-4
......@@ -5,8 +5,7 @@ export fn entry() void {
55}
66
77// error
8// backend=stage2
9// target=native
108//
11// :2:1: error: redeclaration of 'a'
12// :1:1: note: other declaration here
9// :1:4: error: duplicate struct member name 'a'
10// :2:4: note: duplicate name here
11// :1:1: note: struct declared here
test/cases/compile_errors/redefinition_of_enums.zig+3-2
......@@ -5,5 +5,6 @@ const A = enum { x };
55// backend=stage2
66// target=native
77//
8// :2:1: error: redeclaration of 'A'
9// :1:1: note: other declaration here
8// :1:7: error: duplicate struct member name 'A'
9// :2:7: note: duplicate name here
10// :1:1: note: struct declared here
test/cases/compile_errors/redefinition_of_global_variables.zig+3-2
......@@ -5,5 +5,6 @@ var a: i32 = 2;
55// backend=stage2
66// target=native
77//
8// :2:1: error: redeclaration of 'a'
9// :1:1: note: other declaration here
8// :1:5: error: duplicate struct member name 'a'
9// :2:5: note: duplicate name here
10// :1:1: note: struct declared here
test/cases/compile_errors/redefinition_of_struct.zig+3-2
......@@ -5,5 +5,6 @@ const A = struct { y: i32 };
55// backend=stage2
66// target=native
77//
8// :2:1: error: redeclaration of 'A'
9// :1:1: note: other declaration here
8// :1:7: error: duplicate struct member name 'A'
9// :2:7: note: duplicate name here
10// :1:1: note: struct declared here
test/cases/compile_errors/struct_duplicate_field_name.zig+2-2
......@@ -11,6 +11,6 @@ export fn entry() void {
1111// error
1212// target=native
1313//
14// :2:5: error: duplicate struct field name
15// :3:5: note: duplicate field here
14// :2:5: error: duplicate struct member name 'foo'
15// :3:5: note: duplicate name here
1616// :1:11: note: struct declared here
test/cases/compile_errors/union_duplicate_enum_field.zig+2-2
......@@ -12,6 +12,6 @@ export fn foo() void {
1212// error
1313// target=native
1414//
15// :3:5: error: duplicate union field name
16// :4:5: note: duplicate field here
15// :3:5: error: duplicate union member name 'a'
16// :4:5: note: duplicate name here
1717// :2:11: note: union declared here
test/cases/compile_errors/union_duplicate_field_definition.zig+2-2
......@@ -11,6 +11,6 @@ export fn entry() void {
1111// error
1212// target=native
1313//
14// :2:5: error: duplicate union field name
15// :3:5: note: duplicate field here
14// :2:5: error: duplicate union member name 'foo'
15// :3:5: note: duplicate name here
1616// :1:11: note: union declared here
test/cases/function_redeclaration.zig+3-2
......@@ -8,7 +8,8 @@ fn foo() void {
88
99// error
1010//
11// :3:1: error: redeclaration of 'entry'
12// :2:1: note: other declaration here
11// :2:4: error: duplicate struct member name 'entry'
12// :3:4: note: duplicate name here
13// :2:1: note: struct declared here
1314// :6:9: error: local variable shadows declaration of 'foo'
1415// :5:1: note: declared here
test/cases/global_variable_redeclaration.zig+3-2
......@@ -4,5 +4,6 @@ var foo = true;
44
55// error
66//
7// :3:1: error: redeclaration of 'foo'
8// :2:1: note: other declaration here
7// :2:5: error: duplicate struct member name 'foo'
8// :3:5: note: duplicate name here
9// :2:1: note: struct declared here
test/compile_errors.zig+2-2
......@@ -92,7 +92,7 @@ pub fn addCases(ctx: *Cases, b: *std.Build) !void {
9292 \\const a = @import("a.zig");
9393 \\
9494 \\export fn entry() void {
95 \\ _ = a.S.foo(a.S{ .foo = 2, .bar = 2 });
95 \\ _ = a.S.qux(a.S{ .foo = 2, .bar = 2 });
9696 \\}
9797 , &[_][]const u8{
9898 ":4:23: error: value stored in comptime field does not match the default value of the field",
......@@ -102,7 +102,7 @@ pub fn addCases(ctx: *Cases, b: *std.Build) !void {
102102 \\pub const S = struct {
103103 \\ comptime foo: u32 = 1,
104104 \\ bar: u32,
105 \\ pub fn foo(x: @This()) void {
105 \\ pub fn qux(x: @This()) void {
106106 \\ _ = x;
107107 \\ }
108108 \\};