aboutsummaryrefslogtreecommitdiff
path: root/test/compile_errors.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-02-21 14:44:14 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-02-21 14:44:14 -0500
commit1066004b79d014b4c3d10da19c84c679e21b88e5 (patch)
treedb8c1c83788a624d1fab720073255e8c556d59a0 /test/compile_errors.zig
parent2bb795dc455823e76ef3e0c9b3fcee6bcb15fddb (diff)
downloadzig-1066004b79d014b4c3d10da19c84c679e21b88e5.tar.gz
zig-1066004b79d014b4c3d10da19c84c679e21b88e5.zip
better handling of arrays in packed structs
* Separate LoadPtr IR instructions into pass1 and pass2 variants. * Define `type_size_bits` for extern structs to be the same as their `@sizeOf(T) * 8` and allow them in packed structs. * More helpful error messages when trying to use types in packed structs that are not allowed. * Support arrays in packed structs even when they are not byte-aligned. * Add compile error for using arrays in packed structs when the padding bits would be problematic. This is necessary since we do not have packed arrays. closes #677
Diffstat (limited to 'test/compile_errors.zig')
-rw-r--r--test/compile_errors.zig54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
index 07e677b8ed..c39d34b3e9 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -1,6 +1,60 @@
const tests = @import("tests.zig");
pub fn addCases(cases: *tests.CompileErrorContext) void {
+ cases.addTest(
+ "packed struct with fields of not allowed types",
+ \\const A = packed struct {
+ \\ x: anyerror,
+ \\};
+ \\const B = packed struct {
+ \\ x: [2]u24,
+ \\};
+ \\const C = packed struct {
+ \\ x: [1]anyerror,
+ \\};
+ \\const D = packed struct {
+ \\ x: [1]S,
+ \\};
+ \\const E = packed struct {
+ \\ x: [1]U,
+ \\};
+ \\const F = packed struct {
+ \\ x: ?anyerror,
+ \\};
+ \\const G = packed struct {
+ \\ x: Enum,
+ \\};
+ \\export fn entry() void {
+ \\ var a: A = undefined;
+ \\ var b: B = undefined;
+ \\ var r: C = undefined;
+ \\ var d: D = undefined;
+ \\ var e: E = undefined;
+ \\ var f: F = undefined;
+ \\ var g: G = undefined;
+ \\}
+ \\const S = struct {
+ \\ x: i32,
+ \\};
+ \\const U = struct {
+ \\ A: i32,
+ \\ B: u32,
+ \\};
+ \\const Enum = enum {
+ \\ A,
+ \\ B,
+ \\};
+ ,
+ ".tmp_source.zig:2:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation",
+ ".tmp_source.zig:5:5: error: array of 'u24' not allowed in packed struct due to padding bits",
+ ".tmp_source.zig:8:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation",
+ ".tmp_source.zig:11:5: error: non-packed, non-extern struct 'S' not allowed in packed struct; no guaranteed in-memory representation",
+ ".tmp_source.zig:14:5: error: non-packed, non-extern struct 'U' not allowed in packed struct; no guaranteed in-memory representation",
+ ".tmp_source.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation",
+ ".tmp_source.zig:20:5: error: type 'Enum' not allowed in packed struct; no guaranteed in-memory representation",
+ ".tmp_source.zig:38:14: note: enum declaration does not specify an integer tag type",
+ );
+
cases.addCase(x: {
var tc = cases.create(
"deduplicate undeclared identifier",