Skip to content

Commit ba1ce49

Browse files
committed
cases: more stage1 issues test coverage
Closes #11850 Closes #12159
1 parent 8ffa2d7 commit ba1ce49

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

test/cases/compile_errors/invalid_store_to_comptime_field.zig

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ pub export fn entry5() void {
4444
comptime var y = .{ 1, 2 };
4545
y = .{ 3, 4 };
4646
}
47-
// pub export fn entry5() void {
48-
// var x: u32 = 15;
49-
// const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x });
50-
// const S = struct {
51-
// fn foo(_: T) void {}
52-
// };
53-
// _ = S.foo(.{ -1234, 5679, x });
54-
// }
5547
pub export fn entry6() void {
48+
var x: u32 = 15;
49+
const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x });
50+
const S = struct {
51+
fn foo(_: T) void {}
52+
};
53+
_ = S.foo(.{ -1234, 5679, x });
54+
}
55+
pub export fn entry7() void {
5656
const State = struct {
5757
comptime id: bool = true,
5858
fn init(comptime id: bool) @This() {
@@ -61,6 +61,11 @@ pub export fn entry6() void {
6161
};
6262
_ = State.init(false);
6363
}
64+
pub export fn entry8() 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

6570
// error
6671
// target=native
@@ -73,4 +78,6 @@ pub export fn entry6() void {
7378
// :25:29: note: default value set here
7479
// :41:16: error: value stored in comptime field does not match the default value of the field
7580
// :45:12: error: value stored in comptime field does not match the default value of the field
81+
// :53:16: error: value stored in comptime field does not match the default value of the field
82+
// :66:43: error: value stored in comptime field does not match the default value of the field
7683
// :59:35: error: value stored in comptime field does not match the default value of the field
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
const A = struct { x : i32, };
1+
const A = struct { x: i32 };
22
export fn f() void {
3-
var a : A = undefined;
3+
var a: A = undefined;
44
a.foo = 1;
55
const y = a.bar;
66
_ = y;
77
}
88
export fn g() void {
9-
var a : A = undefined;
9+
var a: A = undefined;
1010
const y = a.bar;
1111
_ = y;
1212
}
13+
export 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

1421
// error
1522
// backend=stage2
@@ -18,4 +25,5 @@ export fn g() void {
1825
// :4:7: error: no field named 'foo' in struct 'tmp.A'
1926
// :1:11: note: struct declared here
2027
// :10:17: error: no field named 'bar' in struct 'tmp.A'
21-
28+
// :18:45: error: no field named 'f' in struct 'tmp.e.B'
29+
// :14:15: note: struct declared here

0 commit comments

Comments
 (0)