aboutsummaryrefslogtreecommitdiff
path: root/test/cases/compile_errors
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-08-21 14:27:34 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-08-22 13:54:14 -0700
commitada0010471163a3accca8976185fbb6bb59c914f (patch)
treed5035071ea3cb73677e381c0052e137fded064ac /test/cases/compile_errors
parent6a5463951f0aa11cbdd5575cc78e85cd2ed10b46 (diff)
downloadzig-ada0010471163a3accca8976185fbb6bb59c914f.tar.gz
zig-ada0010471163a3accca8976185fbb6bb59c914f.zip
compiler: move unions into InternPool
There are a couple concepts here worth understanding: Key.UnionType - This type is available *before* resolving the union's fields. The enum tag type, number of fields, and field names, field types, and field alignments are not available with this. InternPool.UnionType - This one can be obtained from the above type with `InternPool.loadUnionType` which asserts that the union's enum tag type has been resolved. This one has all the information available. Additionally: * ZIR: Turn an unused bit into `any_aligned_fields` flag to help semantic analysis know whether a union has explicit alignment on any fields (usually not). * Sema: delete `resolveTypeRequiresComptime` which had the same type signature and near-duplicate logic to `typeRequiresComptime`. - Make opaque types not report comptime-only (this was inconsistent between the two implementations of this function). * Implement accepted proposal #12556 which is a breaking change.
Diffstat (limited to 'test/cases/compile_errors')
-rw-r--r--test/cases/compile_errors/access_inactive_union_field_comptime.zig2
-rw-r--r--test/cases/compile_errors/dereference_anyopaque.zig3
-rw-r--r--test/cases/compile_errors/directly_embedding_opaque_type_in_struct_and_union.zig10
-rw-r--r--test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig8
4 files changed, 12 insertions, 11 deletions
diff --git a/test/cases/compile_errors/access_inactive_union_field_comptime.zig b/test/cases/compile_errors/access_inactive_union_field_comptime.zig
index 2098b19d14..fec57b2b36 100644
--- a/test/cases/compile_errors/access_inactive_union_field_comptime.zig
+++ b/test/cases/compile_errors/access_inactive_union_field_comptime.zig
@@ -1,4 +1,4 @@
-const Enum = enum(u32) { a, b };
+const Enum = enum(u32) { b, a };
const TaggedUnion = union(Enum) {
b: []const u8,
a: []const u8,
diff --git a/test/cases/compile_errors/dereference_anyopaque.zig b/test/cases/compile_errors/dereference_anyopaque.zig
index 6dbbdfe1e2..bb22bc8e2c 100644
--- a/test/cases/compile_errors/dereference_anyopaque.zig
+++ b/test/cases/compile_errors/dereference_anyopaque.zig
@@ -45,8 +45,7 @@ pub export fn entry() void {
// backend=llvm
//
// :11:22: error: comparison of 'void' with null
-// :25:51: error: values of type 'anyopaque' must be comptime-known, but operand value is runtime-known
-// :25:51: note: opaque type 'anyopaque' has undefined size
+// :25:51: error: cannot load opaque type 'anyopaque'
// :25:51: error: values of type 'fn(*anyopaque, usize, u8, usize) ?[*]u8' must be comptime-known, but operand value is runtime-known
// :25:51: note: use '*const fn(*anyopaque, usize, u8, usize) ?[*]u8' for a function pointer type
// :25:51: error: values of type 'fn(*anyopaque, []u8, u8, usize, usize) bool' must be comptime-known, but operand value is runtime-known
diff --git a/test/cases/compile_errors/directly_embedding_opaque_type_in_struct_and_union.zig b/test/cases/compile_errors/directly_embedding_opaque_type_in_struct_and_union.zig
index ace90bccfc..d9f27da4aa 100644
--- a/test/cases/compile_errors/directly_embedding_opaque_type_in_struct_and_union.zig
+++ b/test/cases/compile_errors/directly_embedding_opaque_type_in_struct_and_union.zig
@@ -15,12 +15,12 @@ export fn b() void {
_ = bar;
}
export fn c() void {
- const baz = &@as(opaque {}, undefined);
+ const baz = &@as(O, undefined);
const qux = .{baz.*};
_ = qux;
}
export fn d() void {
- const baz = &@as(opaque {}, undefined);
+ const baz = &@as(O, undefined);
const qux = .{ .a = baz.* };
_ = qux;
}
@@ -33,7 +33,5 @@ export fn d() void {
// :1:11: note: opaque declared here
// :7:10: error: opaque types have unknown size and therefore cannot be directly embedded in unions
// :1:11: note: opaque declared here
-// :19:18: error: opaque types have unknown size and therefore cannot be directly embedded in structs
-// :18:22: note: opaque declared here
-// :24:23: error: opaque types have unknown size and therefore cannot be directly embedded in structs
-// :23:22: note: opaque declared here
+// :19:22: error: cannot load opaque type 'tmp.O'
+// :24:28: error: cannot load opaque type 'tmp.O'
diff --git a/test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig b/test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig
index 48b92460c4..7064ebb1b6 100644
--- a/test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig
+++ b/test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig
@@ -27,6 +27,10 @@ export fn entry7() void {
_ = f;
}
const Opaque = opaque {};
+export fn entry8() void {
+ var e: Opaque = undefined;
+ _ = &e;
+}
// error
// backend=stage2
@@ -39,7 +43,7 @@ const Opaque = opaque {};
// :14:9: error: variable of type 'comptime_float' must be const or comptime
// :14:9: note: to modify this variable at runtime, it must be given an explicit fixed-size number type
// :18:9: error: variable of type '@TypeOf(null)' must be const or comptime
-// :22:20: error: values of type 'tmp.Opaque' must be comptime-known, but operand value is runtime-known
-// :22:20: note: opaque type 'tmp.Opaque' has undefined size
+// :22:20: error: cannot load opaque type 'tmp.Opaque'
// :26:9: error: variable of type 'type' must be const or comptime
// :26:9: note: types are not available at runtime
+// :31:12: error: non-extern variable with opaque type 'tmp.Opaque'