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 {...@@ -5,10 +5,9 @@ export fn entry() usize {
5}5}
66
7// error7// error
8// backend=stage2
9// target=native
10//8//
11// :2:1: error: redeclaration of 'func'9// :1:4: error: duplicate struct member name 'func'
12// :1:1: note: other declaration here10// :2:4: note: duplicate name here
11// :1:1: note: struct declared here
13// :1:11: error: use of undeclared identifier 'bogus'12// :1:11: error: use of undeclared identifier 'bogus'
14// :2:11: error: use of undeclared identifier 'bogus'13// :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 {...@@ -2,6 +2,7 @@ fn foo(a: usize) void {
2 struct {2 struct {
3 const a = 1;3 const a = 1;
4 };4 };
5 _ = a;
5}6}
6fn bar(a: usize) void {7fn bar(a: usize) void {
7 struct {8 struct {
...@@ -18,5 +19,5 @@ fn bar(a: usize) void {...@@ -18,5 +19,5 @@ fn bar(a: usize) void {
18//19//
19// :3:15: error: declaration 'a' shadows function parameter from outer scope20// :3:15: error: declaration 'a' shadows function parameter from outer scope
20// :1:8: note: previous declaration here21// :1:8: note: previous declaration here
21// :9:19: error: declaration 'a' shadows function parameter from outer scope22// :10:19: error: declaration 'a' shadows function parameter from outer scope
22// :6:8: note: previous declaration here23// :7:8: note: previous declaration here
test/cases/compile_errors/duplicate_enum_field.zig+2-2
...@@ -12,6 +12,6 @@ export fn entry() void {...@@ -12,6 +12,6 @@ export fn entry() void {
12// backend=stage212// backend=stage2
13// target=native13// target=native
14//14//
15// :2:5: error: duplicate enum field name15// :2:5: error: duplicate enum member name 'Bar'
16// :3:5: note: duplicate field here16// :3:5: note: duplicate name here
17// :1:13: note: enum declared here17// :1:13: note: enum declared here
test/cases/compile_errors/duplicate_struct_field.zig+5-5
...@@ -24,10 +24,10 @@ export fn b() void {...@@ -24,10 +24,10 @@ export fn b() void {
24// backend=stage224// backend=stage2
25// target=native25// target=native
26//26//
27// :2:5: error: duplicate struct field name27// :2:5: error: duplicate struct member name 'Bar'
28// :3:5: note: duplicate field here28// :3:5: note: duplicate name here
29// :1:13: note: struct declared here29// :1:13: note: struct declared here
30// :7:5: error: duplicate struct field name30// :7:5: error: duplicate struct member name 'a'
31// :9:5: note: duplicate field here31// :9:5: note: duplicate name here
32// :10:5: note: duplicate field here32// :10:5: note: duplicate name here
33// :6:11: note: struct declared here33// :6:11: note: struct declared here
test/cases/compile_errors/duplicate_union_field.zig+2-4
...@@ -8,9 +8,7 @@ export fn entry() void {...@@ -8,9 +8,7 @@ export fn entry() void {
8}8}
99
10// error10// error
11// backend=stage2
12// target=native
13//11//
14// :2:5: error: duplicate union field name12// :2:5: error: duplicate union member name 'Bar'
15// :3:5: note: duplicate field here13// :3:5: note: duplicate name here
16// :1:13: note: union declared here14// :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 {...@@ -8,9 +8,7 @@ pub export fn entry() void {
8}8}
99
10// error10// error
11// backend=stage2
12// target=native
13//11//
14// :3:9: error: duplicate struct field name12// :3:9: error: duplicate struct member name 'e'
15// :4:9: note: duplicate field here13// :4:9: note: duplicate name here
16// :2:22: note: struct declared here14// :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" {}...@@ -6,5 +6,6 @@ test "thingy" {}
6// target=native6// target=native
7// is_test=true7// is_test=true
8//8//
9// :2:1: error: duplicate test name 'thingy'9// :1:6: error: duplicate test name 'thingy'
10// :1:1: note: other test here10// :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 {...@@ -25,21 +25,21 @@ pub export fn entry3() void {
25 const U = struct {25 const U = struct {
26 comptime foo: u32 = 1,26 comptime foo: u32 = 1,
27 bar: u32,27 bar: u32,
28 fn foo(x: @This()) void {28 fn qux(x: @This()) void {
29 _ = x;29 _ = x;
30 }30 }
31 };31 };
32 _ = U.foo(U{ .foo = 2, .bar = 2 });32 _ = U.qux(U{ .foo = 2, .bar = 2 });
33}33}
34pub export fn entry4() void {34pub export fn entry4() void {
35 const U = struct {35 const U = struct {
36 comptime foo: u32 = 1,36 comptime foo: u32 = 1,
37 bar: u32,37 bar: u32,
38 fn foo(x: @This()) void {38 fn qux(x: @This()) void {
39 _ = x;39 _ = x;
40 }40 }
41 };41 };
42 _ = U.foo(.{ .foo = 2, .bar = 2 });42 _ = U.qux(.{ .foo = 2, .bar = 2 });
43}43}
44pub export fn entry5() void {44pub export fn entry5() void {
45 comptime var y = .{ 1, 2 };45 comptime var y = .{ 1, 2 };
test/cases/compile_errors/multiple_function_definitions.zig+3-4
...@@ -5,8 +5,7 @@ export fn entry() void {...@@ -5,8 +5,7 @@ export fn entry() void {
5}5}
66
7// error7// error
8// backend=stage2
9// target=native
10//8//
11// :2:1: error: redeclaration of 'a'9// :1:4: error: duplicate struct member name 'a'
12// :1:1: note: other declaration here10// :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 };...@@ -5,5 +5,6 @@ const A = enum { x };
5// backend=stage25// backend=stage2
6// target=native6// target=native
7//7//
8// :2:1: error: redeclaration of 'A'8// :1:7: error: duplicate struct member name 'A'
9// :1:1: note: other declaration here9// :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;...@@ -5,5 +5,6 @@ var a: i32 = 2;
5// backend=stage25// backend=stage2
6// target=native6// target=native
7//7//
8// :2:1: error: redeclaration of 'a'8// :1:5: error: duplicate struct member name 'a'
9// :1:1: note: other declaration here9// :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 };...@@ -5,5 +5,6 @@ const A = struct { y: i32 };
5// backend=stage25// backend=stage2
6// target=native6// target=native
7//7//
8// :2:1: error: redeclaration of 'A'8// :1:7: error: duplicate struct member name 'A'
9// :1:1: note: other declaration here9// :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 {...@@ -11,6 +11,6 @@ export fn entry() void {
11// error11// error
12// target=native12// target=native
13//13//
14// :2:5: error: duplicate struct field name14// :2:5: error: duplicate struct member name 'foo'
15// :3:5: note: duplicate field here15// :3:5: note: duplicate name here
16// :1:11: note: struct declared here16// :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 {...@@ -12,6 +12,6 @@ export fn foo() void {
12// error12// error
13// target=native13// target=native
14//14//
15// :3:5: error: duplicate union field name15// :3:5: error: duplicate union member name 'a'
16// :4:5: note: duplicate field here16// :4:5: note: duplicate name here
17// :2:11: note: union declared here17// :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 {...@@ -11,6 +11,6 @@ export fn entry() void {
11// error11// error
12// target=native12// target=native
13//13//
14// :2:5: error: duplicate union field name14// :2:5: error: duplicate union member name 'foo'
15// :3:5: note: duplicate field here15// :3:5: note: duplicate name here
16// :1:11: note: union declared here16// :1:11: note: union declared here
test/cases/function_redeclaration.zig+3-2
...@@ -8,7 +8,8 @@ fn foo() void {...@@ -8,7 +8,8 @@ fn foo() void {
88
9// error9// error
10//10//
11// :3:1: error: redeclaration of 'entry'11// :2:4: error: duplicate struct member name 'entry'
12// :2:1: note: other declaration here12// :3:4: note: duplicate name here
13// :2:1: note: struct declared here
13// :6:9: error: local variable shadows declaration of 'foo'14// :6:9: error: local variable shadows declaration of 'foo'
14// :5:1: note: declared here15// :5:1: note: declared here
test/cases/global_variable_redeclaration.zig+3-2
...@@ -4,5 +4,6 @@ var foo = true;...@@ -4,5 +4,6 @@ var foo = true;
44
5// error5// error
6//6//
7// :3:1: error: redeclaration of 'foo'7// :2:5: error: duplicate struct member name 'foo'
8// :2:1: note: other declaration here8// :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 {...@@ -92,7 +92,7 @@ pub fn addCases(ctx: *Cases, b: *std.Build) !void {
92 \\const a = @import("a.zig");92 \\const a = @import("a.zig");
93 \\93 \\
94 \\export fn entry() void {94 \\export fn entry() void {
95 \\ _ = a.S.foo(a.S{ .foo = 2, .bar = 2 });95 \\ _ = a.S.qux(a.S{ .foo = 2, .bar = 2 });
96 \\}96 \\}
97 , &[_][]const u8{97 , &[_][]const u8{
98 ":4:23: error: value stored in comptime field does not match the default value of the field",98 ":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 {...@@ -102,7 +102,7 @@ pub fn addCases(ctx: *Cases, b: *std.Build) !void {
102 \\pub const S = struct {102 \\pub const S = struct {
103 \\ comptime foo: u32 = 1,103 \\ comptime foo: u32 = 1,
104 \\ bar: u32,104 \\ bar: u32,
105 \\ pub fn foo(x: @This()) void {105 \\ pub fn qux(x: @This()) void {
106 \\ _ = x;106 \\ _ = x;
107 \\ }107 \\ }
108 \\};108 \\};