Skip to content

Commit c266a70

Browse files
committed
Update compile error test for field access of opaque type
1 parent f8f25f7 commit c266a70

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/stage1/ir.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22314,6 +22314,8 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
2231422314
prefix_name = "enum ";
2231522315
} else if (bare_struct_type->id == ZigTypeIdUnion) {
2231622316
prefix_name = "union ";
22317+
} else if (bare_struct_type->id == ZigTypeIdOpaque) {
22318+
prefix_name = "opaque type ";
2231722319
} else {
2231822320
prefix_name = "";
2231922321
}

test/compile_errors.zig

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
7373
"tmp.zig:27:24: note: referenced here",
7474
});
7575

76+
cases.add("field access of opaque type",
77+
\\const MyType = opaque {};
78+
\\
79+
\\export fn entry() bool {
80+
\\ var x: i32 = 1;
81+
\\ return bar(@ptrCast(*MyType, &x));
82+
\\}
83+
\\
84+
\\fn bar(x: *MyType) bool {
85+
\\ return x.blah;
86+
\\}
87+
, &[_][]const u8{
88+
"tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'",
89+
});
90+
7691
cases.add("opaque type with field",
7792
\\const Opaque = opaque { foo: i32 };
7893
\\export fn entry() void {
@@ -6976,21 +6991,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
69766991
"tmp.zig:37:29: error: cannot store runtime value in compile time variable",
69776992
});
69786993

6979-
cases.add("field access of opaque type",
6980-
\\const MyType = opaque {};
6981-
\\
6982-
\\export fn entry() bool {
6983-
\\ var x: i32 = 1;
6984-
\\ return bar(@ptrCast(*MyType, &x));
6985-
\\}
6986-
\\
6987-
\\fn bar(x: *MyType) bool {
6988-
\\ return x.blah;
6989-
\\}
6990-
, &[_][]const u8{
6991-
"tmp.zig:9:13: error: type '*MyType' does not support field access",
6992-
});
6993-
69946994
cases.add("invalid legacy unicode escape",
69956995
\\export fn entry() void {
69966996
\\ const a = '\U1234';

0 commit comments

Comments
 (0)