mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
cases: update for new error wording, add coverage for field/decl name conflict
This commit is contained in:
parent
c62487da76
commit
605f2a0978
19 changed files with 68 additions and 49 deletions
|
|
@ -5,10 +5,9 @@ export fn entry() usize {
|
||||||
}
|
}
|
||||||
|
|
||||||
// error
|
// error
|
||||||
// backend=stage2
|
|
||||||
// target=native
|
|
||||||
//
|
//
|
||||||
// :2:1: error: redeclaration of 'func'
|
// :1:4: error: duplicate struct member name 'func'
|
||||||
// :1:1: note: other declaration here
|
// :2:4: note: duplicate name here
|
||||||
|
// :1:1: note: struct declared here
|
||||||
// :1:11: error: use of undeclared identifier 'bogus'
|
// :1:11: error: use of undeclared identifier 'bogus'
|
||||||
// :2:11: error: use of undeclared identifier 'bogus'
|
// :2:11: error: use of undeclared identifier 'bogus'
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ fn foo(a: usize) void {
|
||||||
struct {
|
struct {
|
||||||
const a = 1;
|
const a = 1;
|
||||||
};
|
};
|
||||||
|
_ = a;
|
||||||
}
|
}
|
||||||
fn bar(a: usize) void {
|
fn bar(a: usize) void {
|
||||||
struct {
|
struct {
|
||||||
|
|
@ -18,5 +19,5 @@ fn bar(a: usize) void {
|
||||||
//
|
//
|
||||||
// :3:15: error: declaration 'a' shadows function parameter from outer scope
|
// :3:15: error: declaration 'a' shadows function parameter from outer scope
|
||||||
// :1:8: note: previous declaration here
|
// :1:8: note: previous declaration here
|
||||||
// :9:19: error: declaration 'a' shadows function parameter from outer scope
|
// :10:19: error: declaration 'a' shadows function parameter from outer scope
|
||||||
// :6:8: note: previous declaration here
|
// :7:8: note: previous declaration here
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,6 @@ export fn entry() void {
|
||||||
// backend=stage2
|
// backend=stage2
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :2:5: error: duplicate enum field name
|
// :2:5: error: duplicate enum member name 'Bar'
|
||||||
// :3:5: note: duplicate field here
|
// :3:5: note: duplicate name here
|
||||||
// :1:13: note: enum declared here
|
// :1:13: note: enum declared here
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,10 @@ export fn b() void {
|
||||||
// backend=stage2
|
// backend=stage2
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :2:5: error: duplicate struct field name
|
// :2:5: error: duplicate struct member name 'Bar'
|
||||||
// :3:5: note: duplicate field here
|
// :3:5: note: duplicate name here
|
||||||
// :1:13: note: struct declared here
|
// :1:13: note: struct declared here
|
||||||
// :7:5: error: duplicate struct field name
|
// :7:5: error: duplicate struct member name 'a'
|
||||||
// :9:5: note: duplicate field here
|
// :9:5: note: duplicate name here
|
||||||
// :10:5: note: duplicate field here
|
// :10:5: note: duplicate name here
|
||||||
// :6:11: note: struct declared here
|
// :6:11: note: struct declared here
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,7 @@ export fn entry() void {
|
||||||
}
|
}
|
||||||
|
|
||||||
// error
|
// error
|
||||||
// backend=stage2
|
|
||||||
// target=native
|
|
||||||
//
|
//
|
||||||
// :2:5: error: duplicate union field name
|
// :2:5: error: duplicate union member name 'Bar'
|
||||||
// :3:5: note: duplicate field here
|
// :3:5: note: duplicate name here
|
||||||
// :1:13: note: union declared here
|
// :1:13: note: union declared here
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,7 @@ pub export fn entry() void {
|
||||||
}
|
}
|
||||||
|
|
||||||
// error
|
// error
|
||||||
// backend=stage2
|
|
||||||
// target=native
|
|
||||||
//
|
//
|
||||||
// :3:9: error: duplicate struct field name
|
// :3:9: error: duplicate struct member name 'e'
|
||||||
// :4:9: note: duplicate field here
|
// :4:9: note: duplicate name here
|
||||||
// :2:22: note: struct declared here
|
// :2:22: note: struct declared here
|
||||||
|
|
|
||||||
18
test/cases/compile_errors/field_decl_name_conflict.zig
Normal file
18
test/cases/compile_errors/field_decl_name_conflict.zig
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
foo: u32,
|
||||||
|
bar: u32,
|
||||||
|
qux: u32,
|
||||||
|
|
||||||
|
const foo = 123;
|
||||||
|
|
||||||
|
var bar: u8 = undefined;
|
||||||
|
fn bar() void {}
|
||||||
|
|
||||||
|
// error
|
||||||
|
//
|
||||||
|
// :1:1: error: duplicate struct member name 'foo'
|
||||||
|
// :5:7: note: duplicate name here
|
||||||
|
// :1:1: note: struct declared here
|
||||||
|
// :2:1: error: duplicate struct member name 'bar'
|
||||||
|
// :7:5: note: duplicate name here
|
||||||
|
// :8:4: note: duplicate name here
|
||||||
|
// :1:1: note: struct declared here
|
||||||
|
|
@ -6,5 +6,6 @@ test "thingy" {}
|
||||||
// target=native
|
// target=native
|
||||||
// is_test=true
|
// is_test=true
|
||||||
//
|
//
|
||||||
// :2:1: error: duplicate test name 'thingy'
|
// :1:6: error: duplicate test name 'thingy'
|
||||||
// :1:1: note: other test here
|
// :2:6: note: duplicate test here
|
||||||
|
// :1:1: note: struct declared here
|
||||||
|
|
|
||||||
|
|
@ -25,21 +25,21 @@ pub export fn entry3() void {
|
||||||
const U = struct {
|
const U = struct {
|
||||||
comptime foo: u32 = 1,
|
comptime foo: u32 = 1,
|
||||||
bar: u32,
|
bar: u32,
|
||||||
fn foo(x: @This()) void {
|
fn qux(x: @This()) void {
|
||||||
_ = x;
|
_ = x;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
_ = U.foo(U{ .foo = 2, .bar = 2 });
|
_ = U.qux(U{ .foo = 2, .bar = 2 });
|
||||||
}
|
}
|
||||||
pub export fn entry4() void {
|
pub export fn entry4() void {
|
||||||
const U = struct {
|
const U = struct {
|
||||||
comptime foo: u32 = 1,
|
comptime foo: u32 = 1,
|
||||||
bar: u32,
|
bar: u32,
|
||||||
fn foo(x: @This()) void {
|
fn qux(x: @This()) void {
|
||||||
_ = x;
|
_ = x;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
_ = U.foo(.{ .foo = 2, .bar = 2 });
|
_ = U.qux(.{ .foo = 2, .bar = 2 });
|
||||||
}
|
}
|
||||||
pub export fn entry5() void {
|
pub export fn entry5() void {
|
||||||
comptime var y = .{ 1, 2 };
|
comptime var y = .{ 1, 2 };
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,7 @@ export fn entry() void {
|
||||||
}
|
}
|
||||||
|
|
||||||
// error
|
// error
|
||||||
// backend=stage2
|
|
||||||
// target=native
|
|
||||||
//
|
//
|
||||||
// :2:1: error: redeclaration of 'a'
|
// :1:4: error: duplicate struct member name 'a'
|
||||||
// :1:1: note: other declaration here
|
// :2:4: note: duplicate name here
|
||||||
|
// :1:1: note: struct declared here
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,6 @@ const A = enum { x };
|
||||||
// backend=stage2
|
// backend=stage2
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :2:1: error: redeclaration of 'A'
|
// :1:7: error: duplicate struct member name 'A'
|
||||||
// :1:1: note: other declaration here
|
// :2:7: note: duplicate name here
|
||||||
|
// :1:1: note: struct declared here
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,6 @@ var a: i32 = 2;
|
||||||
// backend=stage2
|
// backend=stage2
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :2:1: error: redeclaration of 'a'
|
// :1:5: error: duplicate struct member name 'a'
|
||||||
// :1:1: note: other declaration here
|
// :2:5: note: duplicate name here
|
||||||
|
// :1:1: note: struct declared here
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,6 @@ const A = struct { y: i32 };
|
||||||
// backend=stage2
|
// backend=stage2
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :2:1: error: redeclaration of 'A'
|
// :1:7: error: duplicate struct member name 'A'
|
||||||
// :1:1: note: other declaration here
|
// :2:7: note: duplicate name here
|
||||||
|
// :1:1: note: struct declared here
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,6 @@ export fn entry() void {
|
||||||
// error
|
// error
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :2:5: error: duplicate struct field name
|
// :2:5: error: duplicate struct member name 'foo'
|
||||||
// :3:5: note: duplicate field here
|
// :3:5: note: duplicate name here
|
||||||
// :1:11: note: struct declared here
|
// :1:11: note: struct declared here
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,6 @@ export fn foo() void {
|
||||||
// error
|
// error
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :3:5: error: duplicate union field name
|
// :3:5: error: duplicate union member name 'a'
|
||||||
// :4:5: note: duplicate field here
|
// :4:5: note: duplicate name here
|
||||||
// :2:11: note: union declared here
|
// :2:11: note: union declared here
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,6 @@ export fn entry() void {
|
||||||
// error
|
// error
|
||||||
// target=native
|
// target=native
|
||||||
//
|
//
|
||||||
// :2:5: error: duplicate union field name
|
// :2:5: error: duplicate union member name 'foo'
|
||||||
// :3:5: note: duplicate field here
|
// :3:5: note: duplicate name here
|
||||||
// :1:11: note: union declared here
|
// :1:11: note: union declared here
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@ fn foo() void {
|
||||||
|
|
||||||
// error
|
// error
|
||||||
//
|
//
|
||||||
// :3:1: error: redeclaration of 'entry'
|
// :2:4: error: duplicate struct member name 'entry'
|
||||||
// :2:1: note: other declaration here
|
// :3:4: note: duplicate name here
|
||||||
|
// :2:1: note: struct declared here
|
||||||
// :6:9: error: local variable shadows declaration of 'foo'
|
// :6:9: error: local variable shadows declaration of 'foo'
|
||||||
// :5:1: note: declared here
|
// :5:1: note: declared here
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,6 @@ var foo = true;
|
||||||
|
|
||||||
// error
|
// error
|
||||||
//
|
//
|
||||||
// :3:1: error: redeclaration of 'foo'
|
// :2:5: error: duplicate struct member name 'foo'
|
||||||
// :2:1: note: other declaration here
|
// :3:5: note: duplicate name here
|
||||||
|
// :2:1: note: struct declared here
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ pub fn addCases(ctx: *Cases, b: *std.Build) !void {
|
||||||
\\const a = @import("a.zig");
|
\\const a = @import("a.zig");
|
||||||
\\
|
\\
|
||||||
\\export fn entry() void {
|
\\export fn entry() void {
|
||||||
\\ _ = a.S.foo(a.S{ .foo = 2, .bar = 2 });
|
\\ _ = a.S.qux(a.S{ .foo = 2, .bar = 2 });
|
||||||
\\}
|
\\}
|
||||||
, &[_][]const u8{
|
, &[_][]const u8{
|
||||||
":4:23: error: value stored in comptime field does not match the default value of the field",
|
":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 {
|
||||||
\\pub const S = struct {
|
\\pub const S = struct {
|
||||||
\\ comptime foo: u32 = 1,
|
\\ comptime foo: u32 = 1,
|
||||||
\\ bar: u32,
|
\\ bar: u32,
|
||||||
\\ pub fn foo(x: @This()) void {
|
\\ pub fn qux(x: @This()) void {
|
||||||
\\ _ = x;
|
\\ _ = x;
|
||||||
\\ }
|
\\ }
|
||||||
\\};
|
\\};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue