aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2023-06-26 20:41:42 +0100
committerAndrew Kelley <andrew@ziglang.org>2023-06-26 16:20:33 -0700
commit88284c124a0d930541f02ae9727118c0724f93f9 (patch)
treeb55a7334f61f7c8a9516ee66e44aa4504d708d3a /test
parentbbda053f9e309128ee4b2eb1a5b886aeb30fcabf (diff)
downloadzig-88284c124a0d930541f02ae9727118c0724f93f9.tar.gz
zig-88284c124a0d930541f02ae9727118c0724f93f9.zip
AstGen: fix result locations for elements of typed array init
Resolves: #16226
Diffstat (limited to 'test')
-rw-r--r--test/behavior/array.zig29
-rw-r--r--test/cases/compile_errors/discarded_array_bad_elem_type.zig12
2 files changed, 41 insertions, 0 deletions
diff --git a/test/behavior/array.zig b/test/behavior/array.zig
index bc8176aa9c..82313cddc7 100644
--- a/test/behavior/array.zig
+++ b/test/behavior/array.zig
@@ -719,3 +719,32 @@ test "pointer to array has ptr field" {
try std.testing.expect(arr.ptr[3] == 40);
try std.testing.expect(arr.ptr[4] == 50);
}
+
+test "discarded array init preserves result location" {
+ const S = struct {
+ fn f(p: *u32) u16 {
+ p.* += 1;
+ return 0;
+ }
+ };
+
+ var x: u32 = 0;
+ _ = [2]u8{
+ @intCast(S.f(&x)),
+ @intCast(S.f(&x)),
+ };
+
+ // Ensure function was run
+ try expect(x == 2);
+}
+
+test "array init with no result location has result type" {
+ const x = .{ .foo = [2]u16{
+ @intCast(10),
+ @intCast(20),
+ } };
+
+ try expect(x.foo.len == 2);
+ try expect(x.foo[0] == 10);
+ try expect(x.foo[1] == 20);
+}
diff --git a/test/cases/compile_errors/discarded_array_bad_elem_type.zig b/test/cases/compile_errors/discarded_array_bad_elem_type.zig
new file mode 100644
index 0000000000..edc64e40b0
--- /dev/null
+++ b/test/cases/compile_errors/discarded_array_bad_elem_type.zig
@@ -0,0 +1,12 @@
+export fn foo() void {
+ _ = [2]u16{
+ "hello",
+ "world",
+ };
+}
+
+// error
+// backend=llvm
+// target=native
+//
+// :3:9: error: expected type 'u16', found '*const [5:0]u8'