Update compile error test for field access of opaque type

This commit is contained in:
Tadeo Kondrak 2020-09-26 11:55:56 -06:00
parent 6b8ae6fffb
commit bf4bfe54ac
No known key found for this signature in database
GPG Key ID: D41E092CA43F1D8B
2 changed files with 17 additions and 15 deletions

View File

@ -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 = "";
}

View File

@ -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';