Skip to content

Commit 352c718

Browse files
committed
Sema: improve struct/union field error locations
Closes #14206
1 parent 2d617c4 commit 352c718

12 files changed

Lines changed: 194 additions & 94 deletions

src/Sema.zig

Lines changed: 142 additions & 59 deletions
Large diffs are not rendered by default.

test/cases/compile_errors/directly_embedding_opaque_type_in_struct_and_union.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ export fn d() void {
2929
// backend=stage2
3030
// target=native
3131
//
32-
// :3:5: error: opaque types have unknown size and therefore cannot be directly embedded in structs
32+
// :3:8: error: opaque types have unknown size and therefore cannot be directly embedded in structs
3333
// :1:11: note: opaque declared here
34-
// :7:5: error: opaque types have unknown size and therefore cannot be directly embedded in unions
34+
// :7:10: error: opaque types have unknown size and therefore cannot be directly embedded in unions
3535
// :19:18: error: opaque types have unknown size and therefore cannot be directly embedded in structs
3636
// :18:22: note: opaque declared here
3737
// :24:23: error: opaque types have unknown size and therefore cannot be directly embedded in structs

test/cases/compile_errors/extern_struct_with_extern-compatible_but_inferred_integer_tag_type.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export fn entry() void {
3939
// backend=stage2
4040
// target=native
4141
//
42-
// :31:5: error: extern structs cannot contain fields of type 'tmp.E'
43-
// :31:5: note: enum tag type 'u9' is not extern compatible
44-
// :31:5: note: only integers with power of two bits are extern compatible
42+
// :31:8: error: extern structs cannot contain fields of type 'tmp.E'
43+
// :31:8: note: enum tag type 'u9' is not extern compatible
44+
// :31:8: note: only integers with power of two bits are extern compatible
4545
// :1:15: note: enum declared here

test/cases/compile_errors/extern_struct_with_non-extern-compatible_integer_tag_type.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export fn entry() void {
1111
// backend=stage2
1212
// target=native
1313
//
14-
// :3:5: error: extern structs cannot contain fields of type 'tmp.E'
15-
// :3:5: note: enum tag type 'u31' is not extern compatible
16-
// :3:5: note: only integers with power of two bits are extern compatible
14+
// :3:8: error: extern structs cannot contain fields of type 'tmp.E'
15+
// :3:8: note: enum tag type 'u31' is not extern compatible
16+
// :3:8: note: only integers with power of two bits are extern compatible
1717
// :1:15: note: enum declared here
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const Parser = @This();
2+
fn Chunk() type {
3+
return struct {
4+
const Self = @This();
5+
};
6+
}
7+
parser_chunk: Chunk,
8+
9+
comptime {
10+
_ = @sizeOf(@This()) + 1;
11+
}
12+
13+
// error
14+
// backend=stage2
15+
// target=native
16+
//
17+
// :7:15: error: expected type 'type', found 'fn() type'

test/cases/compile_errors/invalid_optional_type_in_extern_struct.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ export fn testf(fluff: *stroo) void { _ = fluff; }
77
// backend=stage2
88
// target=native
99
//
10-
// :2:5: error: extern structs cannot contain fields of type '?[*c]u8'
11-
// :2:5: note: only pointer like optionals are extern compatible
10+
// :2:10: error: extern structs cannot contain fields of type '?[*c]u8'
11+
// :2:10: note: only pointer like optionals are extern compatible

test/cases/compile_errors/noreturn_struct_field.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ comptime {
99
// backend=stage2
1010
// target=native
1111
//
12-
// :2:5: error: struct fields cannot be 'noreturn'
12+
// :2:8: error: struct fields cannot be 'noreturn'

test/cases/compile_errors/old_fn_ptr_in_extern_context.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ comptime {
1212
// backend=stage2
1313
// target=native
1414
//
15-
// :2:5: error: extern structs cannot contain fields of type 'fn() callconv(.C) void'
16-
// :2:5: note: type has no guaranteed in-memory representation
17-
// :2:5: note: use '*const ' to make a function pointer type
15+
// :2:8: error: extern structs cannot contain fields of type 'fn() callconv(.C) void'
16+
// :2:8: note: type has no guaranteed in-memory representation
17+
// :2:8: note: use '*const ' to make a function pointer type
1818
// :8:13: error: C pointers cannot point to non-C-ABI-compatible type '[4]fn() callconv(.C) void'
1919
// :8:13: note: type has no guaranteed in-memory representation
2020
// :8:13: note: use '*const ' to make a function pointer type

test/cases/compile_errors/packed_struct_with_fields_of_not_allowed_types.zig

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,22 @@ export fn entry12() void {
7070
// backend=llvm
7171
// target=native
7272
//
73-
// :3:9: error: packed structs cannot contain fields of type 'anyerror'
74-
// :3:9: note: type has no guaranteed in-memory representation
75-
// :8:9: error: packed structs cannot contain fields of type '[2]u24'
76-
// :8:9: note: type has no guaranteed in-memory representation
77-
// :13:9: error: packed structs cannot contain fields of type 'anyerror!u32'
78-
// :13:9: note: type has no guaranteed in-memory representation
79-
// :18:9: error: packed structs cannot contain fields of type 'tmp.S'
80-
// :18:9: note: only packed structs layout are allowed in packed types
73+
// :3:12: error: packed structs cannot contain fields of type 'anyerror'
74+
// :3:12: note: type has no guaranteed in-memory representation
75+
// :8:12: error: packed structs cannot contain fields of type '[2]u24'
76+
// :8:12: note: type has no guaranteed in-memory representation
77+
// :13:20: error: packed structs cannot contain fields of type 'anyerror!u32'
78+
// :13:20: note: type has no guaranteed in-memory representation
79+
// :18:12: error: packed structs cannot contain fields of type 'tmp.S'
80+
// :18:12: note: only packed structs layout are allowed in packed types
8181
// :56:11: note: struct declared here
82-
// :23:9: error: packed structs cannot contain fields of type 'tmp.U'
83-
// :23:9: note: only packed unions layout are allowed in packed types
82+
// :23:12: error: packed structs cannot contain fields of type 'tmp.U'
83+
// :23:12: note: only packed unions layout are allowed in packed types
8484
// :59:18: note: union declared here
85-
// :28:9: error: packed structs cannot contain fields of type '?anyerror'
86-
// :28:9: note: type has no guaranteed in-memory representation
87-
// :38:9: error: packed structs cannot contain fields of type 'fn() void'
88-
// :38:9: note: type has no guaranteed in-memory representation
89-
// :38:9: note: use '*const ' to make a function pointer type
90-
// :65:28: error: packed structs cannot contain fields of type '[]u8'
91-
// :65:28: note: slices have no guaranteed in-memory representation
85+
// :28:12: error: packed structs cannot contain fields of type '?anyerror'
86+
// :28:12: note: type has no guaranteed in-memory representation
87+
// :38:12: error: packed structs cannot contain fields of type 'fn() void'
88+
// :38:12: note: type has no guaranteed in-memory representation
89+
// :38:12: note: use '*const ' to make a function pointer type
90+
// :65:31: error: packed structs cannot contain fields of type '[]u8'
91+
// :65:31: note: slices have no guaranteed in-memory representation

test/cases/compile_errors/packed_union_with_automatic_layout_field.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ export fn entry() void {
1515
// backend=stage2
1616
// target=native
1717
//
18-
// :6:5: error: packed unions cannot contain fields of type 'tmp.Foo'
19-
// :6:5: note: only packed structs layout are allowed in packed types
18+
// :6:8: error: packed unions cannot contain fields of type 'tmp.Foo'
19+
// :6:8: note: only packed structs layout are allowed in packed types
2020
// :1:13: note: struct declared here

0 commit comments

Comments
 (0)