Commit 06d0dac0fb
Changed files (2)
src
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;
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",