diff --git a/src/analyze.cpp b/src/analyze.cpp index 7712f0f707..c7bd7094d7 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -2893,7 +2893,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) { return ErrorSemanticAnalyzeFail; } if (field_is_opaque_type) { - add_node_error(g, field_node->data.struct_field.type, + add_node_error(g, field_node, buf_sprintf("opaque types have unknown size and therefore cannot be directly embedded in structs")); struct_type->data.structure.resolve_status = ResolveStatusInvalid; return ErrorSemanticAnalyzeFail; @@ -3185,7 +3185,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { return ErrorSemanticAnalyzeFail; } if (field_is_opaque_type) { - add_node_error(g, field_node->data.struct_field.type, + add_node_error(g, field_node, buf_create_from_str( "opaque types have unknown size and therefore cannot be directly embedded in unions")); union_type->data.unionation.resolve_status = ResolveStatusInvalid; diff --git a/test/compile_errors.zig b/test/compile_errors.zig index e402197a8e..2b74d8fc77 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -1610,9 +1610,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn b() void { \\ var bar: Bar = undefined; \\} + \\export fn c() void { + \\ var baz: *@OpaqueType() = undefined; + \\ const qux = .{baz.*}; + \\} , &[_][]const u8{ - "tmp.zig:3:8: error: opaque types have unknown size and therefore cannot be directly embedded in structs", - "tmp.zig:7:10: error: opaque types have unknown size and therefore cannot be directly embedded in unions", + "tmp.zig:3:5: error: opaque types have unknown size and therefore cannot be directly embedded in structs", + "tmp.zig:7:5: error: opaque types have unknown size and therefore cannot be directly embedded in unions", + "tmp.zig:17:22: error: opaque types have unknown size and therefore cannot be directly embedded in structs", }); cases.add("implicit cast between C pointer and Zig pointer - bad const/align/child",