commit 06d0dac0fb58c2d20036e34f5c1a1bc9c386c189 (tree)
parent f90fe1f8f2be6ffa1c19997d123e12310d9e04b5
Author: LemonBoy <thatlemon@gmail.com>
Date: Sun, 8 Mar 2020 19:48:35 +0100
ir: Prevent crash in compiler error
Anonymous containers have no struct_field->type AstNode set, let's
always use the field node itself to make the error messages consistent.
Closes #4691
Diffstat:
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git 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
@@ -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",