Skip to content

Commit bf4bfe5

Browse files
committed
Update compile error test for field access of opaque type
1 parent 6b8ae6f commit bf4bfe5

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
@@ -22387,6 +22387,8 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
2238722387
prefix_name = "enum ";
2238822388
} else if (bare_struct_type->id == ZigTypeIdUnion) {
2238922389
prefix_name = "union ";
22390+
} else if (bare_struct_type->id == ZigTypeIdOpaque) {
22391+
prefix_name = "opaque type ";
2239022392
} else {
2239122393
prefix_name = "";
2239222394
}

test/compile_errors.zig

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

129+
cases.add("field access of opaque type",
130+
\\const MyType = opaque {};
131+
\\
132+
\\export fn entry() bool {
133+
\\ var x: i32 = 1;
134+
\\ return bar(@ptrCast(*MyType, &x));
135+
\\}
136+
\\
137+
\\fn bar(x: *MyType) bool {
138+
\\ return x.blah;
139+
\\}
140+
, &[_][]const u8{
141+
"tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'",
142+
});
143+
129144
cases.add("opaque type with field",
130145
\\const Opaque = opaque { foo: i32 };
131146
\\export fn entry() void {
@@ -7029,21 +7044,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
70297044
"tmp.zig:37:29: error: cannot store runtime value in compile time variable",
70307045
});
70317046

7032-
cases.add("field access of opaque type",
7033-
\\const MyType = opaque {};
7034-
\\
7035-
\\export fn entry() bool {
7036-
\\ var x: i32 = 1;
7037-
\\ return bar(@ptrCast(*MyType, &x));
7038-
\\}
7039-
\\
7040-
\\fn bar(x: *MyType) bool {
7041-
\\ return x.blah;
7042-
\\}
7043-
, &[_][]const u8{
7044-
"tmp.zig:9:13: error: type '*MyType' does not support field access",
7045-
});
7046-
70477047
cases.add("invalid legacy unicode escape",
70487048
\\export fn entry() void {
70497049
\\ const a = '\U1234';

0 commit comments

Comments
 (0)