Skip to content

Commit 614f108

Browse files
committed
Update compile error test for field access of opaque type
1 parent b4224a0 commit 614f108

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
@@ -2,6 +2,21 @@ const tests = @import("tests.zig");
22
const std = @import("std");
33

44
pub fn addCases(cases: *tests.CompileErrorContext) void {
5+
cases.add("field access of opaque type",
6+
\\const MyType = opaque {};
7+
\\
8+
\\export fn entry() bool {
9+
\\ var x: i32 = 1;
10+
\\ return bar(@ptrCast(*MyType, &x));
11+
\\}
12+
\\
13+
\\fn bar(x: *MyType) bool {
14+
\\ return x.blah;
15+
\\}
16+
, &[_][]const u8{
17+
"tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'",
18+
});
19+
520
cases.add("opaque type with field",
621
\\const Opaque = opaque { foo: i32 };
722
\\export fn entry() void {
@@ -6893,21 +6908,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
68936908
"tmp.zig:37:29: error: cannot store runtime value in compile time variable",
68946909
});
68956910

6896-
cases.add("field access of opaque type",
6897-
\\const MyType = opaque {};
6898-
\\
6899-
\\export fn entry() bool {
6900-
\\ var x: i32 = 1;
6901-
\\ return bar(@ptrCast(*MyType, &x));
6902-
\\}
6903-
\\
6904-
\\fn bar(x: *MyType) bool {
6905-
\\ return x.blah;
6906-
\\}
6907-
, &[_][]const u8{
6908-
"tmp.zig:9:13: error: type '*MyType' does not support field access",
6909-
});
6910-
69116911
cases.add("invalid legacy unicode escape",
69126912
\\export fn entry() void {
69136913
\\ const a = '\U1234';

0 commit comments

Comments
 (0)