Skip to content

Commit d308bef

Browse files
committed
Update compile error test for field access of opaque type
1 parent 7c02a1d commit d308bef

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/ir.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22310,6 +22310,8 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
2231022310
prefix_name = "enum ";
2231122311
} else if (bare_struct_type->id == ZigTypeIdUnion) {
2231222312
prefix_name = "union ";
22313+
} else if (bare_struct_type->id == ZigTypeIdOpaque) {
22314+
prefix_name = "opaque type ";
2231322315
} else {
2231422316
prefix_name = "";
2231522317
}

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 {
@@ -6885,21 +6900,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
68856900
"tmp.zig:37:29: error: cannot store runtime value in compile time variable",
68866901
});
68876902

6888-
cases.add("field access of opaque type",
6889-
\\const MyType = opaque {};
6890-
\\
6891-
\\export fn entry() bool {
6892-
\\ var x: i32 = 1;
6893-
\\ return bar(@ptrCast(*MyType, &x));
6894-
\\}
6895-
\\
6896-
\\fn bar(x: *MyType) bool {
6897-
\\ return x.blah;
6898-
\\}
6899-
, &[_][]const u8{
6900-
"tmp.zig:9:13: error: type '*MyType' does not support field access",
6901-
});
6902-
69036903
cases.add("invalid legacy unicode escape",
69046904
\\export fn entry() void {
69056905
\\ const a = '\U1234';

0 commit comments

Comments
 (0)