aboutsummaryrefslogtreecommitdiff
path: root/test/cases/compile_errors/struct_depends_on_pointer_alignment.zig
diff options
context:
space:
mode:
authorkcbanner <kcbanner@gmail.com>2023-10-21 16:49:30 -0400
committermlugg <mlugg@mlugg.co.uk>2023-11-07 00:49:35 +0000
commitf10499be0a16ec58d98387b49189401f2af2094f (patch)
tree1dee8acd698e9bb489a9926004d4cdf16f7ce72d /test/cases/compile_errors/struct_depends_on_pointer_alignment.zig
parent234693bcbba6f55ff6e975ddbedf0fad4dfaa8f1 (diff)
downloadzig-f10499be0a16ec58d98387b49189401f2af2094f.tar.gz
zig-f10499be0a16ec58d98387b49189401f2af2094f.zip
sema: analyze field init bodies in a second pass
This change allows struct field inits to use layout information of their own struct without causing a circular dependency. `semaStructFields` caches the ranges of the init bodies in the `StructType` trailing data. The init bodies are then resolved by `resolveStructFieldInits`, which is called before the inits are actually required. Within the init bodies, the struct decl's instruction is repurposed to refer to the field type itself. This is to allow us to easily rebuild the inst_map mapping required for the init body instructions to refer to the field type. Thanks to @mlugg for the guidance on this one!
Diffstat (limited to 'test/cases/compile_errors/struct_depends_on_pointer_alignment.zig')
-rw-r--r--test/cases/compile_errors/struct_depends_on_pointer_alignment.zig11
1 files changed, 11 insertions, 0 deletions
diff --git a/test/cases/compile_errors/struct_depends_on_pointer_alignment.zig b/test/cases/compile_errors/struct_depends_on_pointer_alignment.zig
new file mode 100644
index 0000000000..ca15cc6bf2
--- /dev/null
+++ b/test/cases/compile_errors/struct_depends_on_pointer_alignment.zig
@@ -0,0 +1,11 @@
+const S = struct {
+ next: ?*align(1) S align(128),
+};
+
+export fn entry() usize {
+ return @alignOf(S);
+}
+
+// error
+//
+// :1:11: error: struct layout depends on being pointer aligned