Skip to content

Commit 6eacae5

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

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
@@ -38,6 +38,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3838
"tmp.zig:2:20: error: TypeInfo.Enum.tag_type must be an integer type, not 'bool'",
3939
});
4040

41+
cases.add("field access of opaque type",
42+
\\const MyType = opaque {};
43+
\\
44+
\\export fn entry() bool {
45+
\\ var x: i32 = 1;
46+
\\ return bar(@ptrCast(*MyType, &x));
47+
\\}
48+
\\
49+
\\fn bar(x: *MyType) bool {
50+
\\ return x.blah;
51+
\\}
52+
, &[_][]const u8{
53+
"tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'",
54+
});
55+
4156
cases.add("opaque type with field",
4257
\\const Opaque = opaque { foo: i32 };
4358
\\export fn entry() void {
@@ -6929,21 +6944,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
69296944
"tmp.zig:37:29: error: cannot store runtime value in compile time variable",
69306945
});
69316946

6932-
cases.add("field access of opaque type",
6933-
\\const MyType = opaque {};
6934-
\\
6935-
\\export fn entry() bool {
6936-
\\ var x: i32 = 1;
6937-
\\ return bar(@ptrCast(*MyType, &x));
6938-
\\}
6939-
\\
6940-
\\fn bar(x: *MyType) bool {
6941-
\\ return x.blah;
6942-
\\}
6943-
, &[_][]const u8{
6944-
"tmp.zig:9:13: error: type '*MyType' does not support field access",
6945-
});
6946-
69476947
cases.add("invalid legacy unicode escape",
69486948
\\export fn entry() void {
69496949
\\ const a = '\U1234';

0 commit comments

Comments
 (0)