diff --git a/src/stage1/ir.cpp b/src/stage1/ir.cpp index ad58f23ec3..002b7f3c87 100644 --- a/src/stage1/ir.cpp +++ b/src/stage1/ir.cpp @@ -22387,6 +22387,8 @@ static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira, prefix_name = "enum "; } else if (bare_struct_type->id == ZigTypeIdUnion) { prefix_name = "union "; + } else if (bare_struct_type->id == ZigTypeIdOpaque) { + prefix_name = "opaque type "; } else { prefix_name = ""; } diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 6c2e96fc5e..d5c4fd3ec1 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -126,6 +126,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "tmp.zig:27:24: note: referenced here", }); + cases.add("field access of opaque type", + \\const MyType = opaque {}; + \\ + \\export fn entry() bool { + \\ var x: i32 = 1; + \\ return bar(@ptrCast(*MyType, &x)); + \\} + \\ + \\fn bar(x: *MyType) bool { + \\ return x.blah; + \\} + , &[_][]const u8{ + "tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'", + }); + cases.add("opaque type with field", \\const Opaque = opaque { foo: i32 }; \\export fn entry() void { @@ -7029,21 +7044,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "tmp.zig:37:29: error: cannot store runtime value in compile time variable", }); - cases.add("field access of opaque type", - \\const MyType = opaque {}; - \\ - \\export fn entry() bool { - \\ var x: i32 = 1; - \\ return bar(@ptrCast(*MyType, &x)); - \\} - \\ - \\fn bar(x: *MyType) bool { - \\ return x.blah; - \\} - , &[_][]const u8{ - "tmp.zig:9:13: error: type '*MyType' does not support field access", - }); - cases.add("invalid legacy unicode escape", \\export fn entry() void { \\ const a = '\U1234';