aboutsummaryrefslogtreecommitdiff
path: root/test/cases/compile_errors
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2023-06-13 15:17:31 +0100
committermlugg <mlugg@mlugg.co.uk>2023-06-13 21:48:18 +0100
commitc9531eb833e1e2c432dc2bfb0ca3b25622b7001e (patch)
tree7cdae51f8762b670aed003b3654ff429a731146d /test/cases/compile_errors
parent854f26ad8ac8dc39ef7ad60f86588c0c5dba131a (diff)
downloadzig-c9531eb833e1e2c432dc2bfb0ca3b25622b7001e.tar.gz
zig-c9531eb833e1e2c432dc2bfb0ca3b25622b7001e.zip
Sema: rewrite peer type resolution
The existing logic for peer type resolution was quite convoluted and buggy. This rewrite makes it much more resilient, readable, and extensible. The algorithm works by first iterating over the types to select a "strategy", then applying that strategy, possibly applying peer resolution recursively. Several new tests have been added to cover cases which the old logic did not correctly handle. Resolves: #15138 Resolves: #15644 Resolves: #15693 Resolves: #15709 Resolves: #15752
Diffstat (limited to 'test/cases/compile_errors')
-rw-r--r--test/cases/compile_errors/compare_optional_to_non-optional_with_invalid_types.zig37
-rw-r--r--test/cases/compile_errors/compare_optional_to_non_optional_with_incomparable_type.zig11
-rw-r--r--test/cases/compile_errors/invalid_peer_type_resolution.zig50
3 files changed, 61 insertions, 37 deletions
diff --git a/test/cases/compile_errors/compare_optional_to_non-optional_with_invalid_types.zig b/test/cases/compile_errors/compare_optional_to_non-optional_with_invalid_types.zig
deleted file mode 100644
index 0339ac034e..0000000000
--- a/test/cases/compile_errors/compare_optional_to_non-optional_with_invalid_types.zig
+++ /dev/null
@@ -1,37 +0,0 @@
-export fn inconsistentChildType() void {
- var x: ?i32 = undefined;
- const y: comptime_int = 10;
- _ = (x == y);
-}
-export fn optionalToOptional() void {
- var x: ?i32 = undefined;
- var y: ?i32 = undefined;
- _ = (x == y);
-}
-export fn optionalVector() void {
- var x: ?@Vector(10, i32) = undefined;
- var y: @Vector(10, i32) = undefined;
- _ = (x == y);
-}
-export fn optionalVector2() void {
- var x: ?@Vector(10, i32) = undefined;
- var y: @Vector(11, i32) = undefined;
- _ = (x == y);
-}
-export fn invalidChildType() void {
- var x: ?[3]i32 = undefined;
- var y: [3]i32 = undefined;
- _ = (x == y);
-}
-
-// error
-// backend=llvm
-// target=native
-//
-// :4:12: error: incompatible types: '?i32' and 'comptime_int'
-// :4:10: note: type '?i32' here
-// :4:15: note: type 'comptime_int' here
-// :19:12: error: incompatible types: '?@Vector(10, i32)' and '@Vector(11, i32)'
-// :19:10: note: type '?@Vector(10, i32)' here
-// :19:15: note: type '@Vector(11, i32)' here
-// :24:12: error: operator == not allowed for type '?[3]i32'
diff --git a/test/cases/compile_errors/compare_optional_to_non_optional_with_incomparable_type.zig b/test/cases/compile_errors/compare_optional_to_non_optional_with_incomparable_type.zig
new file mode 100644
index 0000000000..653b7ffcfb
--- /dev/null
+++ b/test/cases/compile_errors/compare_optional_to_non_optional_with_incomparable_type.zig
@@ -0,0 +1,11 @@
+export fn entry() void {
+ var x: ?[3]i32 = undefined;
+ var y: [3]i32 = undefined;
+ _ = (x == y);
+}
+
+// error
+// backend=llvm
+// target=native
+//
+// :4:12: error: operator == not allowed for type '?[3]i32'
diff --git a/test/cases/compile_errors/invalid_peer_type_resolution.zig b/test/cases/compile_errors/invalid_peer_type_resolution.zig
new file mode 100644
index 0000000000..d82986a60a
--- /dev/null
+++ b/test/cases/compile_errors/invalid_peer_type_resolution.zig
@@ -0,0 +1,50 @@
+export fn optionalVector() void {
+ var x: ?@Vector(10, i32) = undefined;
+ var y: @Vector(11, i32) = undefined;
+ _ = @TypeOf(x, y);
+}
+export fn badTupleField() void {
+ var x = .{ @as(u8, 0), @as(u32, 1) };
+ var y = .{ @as(u8, 1), "hello" };
+ _ = @TypeOf(x, y);
+}
+export fn badNestedField() void {
+ const x = .{ .foo = "hi", .bar = .{ 0, 1 } };
+ const y = .{ .foo = "hello", .bar = .{ 2, "hi" } };
+ _ = @TypeOf(x, y);
+}
+export fn incompatiblePointers() void {
+ const x: []const u8 = "foo";
+ const y: [*:0]const u8 = "bar";
+ _ = @TypeOf(x, y);
+}
+export fn incompatiblePointers4() void {
+ const a: *const [5]u8 = "hello";
+ const b: *const [3:0]u8 = "foo";
+ const c: []const u8 = "baz"; // The conflict must be reported against this element!
+ const d: [*]const u8 = "bar";
+ _ = @TypeOf(a, b, c, d);
+}
+
+// error
+// backend=llvm
+// target=native
+//
+// :4:9: error: incompatible types: '?@Vector(10, i32)' and '@Vector(11, i32)'
+// :4:17: note: type '?@Vector(10, i32)' here
+// :4:20: note: type '@Vector(11, i32)' here
+// :9:9: error: struct field '1' has conflicting types
+// :9:9: note: incompatible types: 'u32' and '*const [5:0]u8'
+// :9:17: note: type 'u32' here
+// :9:20: note: type '*const [5:0]u8' here
+// :14:9: error: struct field 'bar' has conflicting types
+// :14:9: note: struct field '1' has conflicting types
+// :14:9: note: incompatible types: 'comptime_int' and '*const [2:0]u8'
+// :14:17: note: type 'comptime_int' here
+// :14:20: note: type '*const [2:0]u8' here
+// :19:9: error: incompatible types: '[]const u8' and '[*:0]const u8'
+// :19:17: note: type '[]const u8' here
+// :19:20: note: type '[*:0]const u8' here
+// :26:9: error: incompatible types: '[]const u8' and '[*]const u8'
+// :26:23: note: type '[]const u8' here
+// :26:26: note: type '[*]const u8' here