1export fn entry1() void {
2 var array: [2]u16 = .{ 1, 2 };
3 const slice: []const u16 = &array;
4 foo(slice);
5}
6
7export fn entry2() void {
8 const slice: []const u16 = undefined;
9 foo(slice);
10}
11
12export fn entry3() void {
13 comptime var slice: []const u16 = &.{ 1, 2 };
14 slice.len = undefined;
15 foo(slice);
16}
17
18export fn entry4() void {
19 const slice: []const u16 = &.{ 1, 2, 3 };
20 foo(slice);
21}
22
23export fn entry5() void {
24 const slice: []const u8 = &.{ 1, 2 };
25 foo(slice);
26}
27
28fn foo(x: *const [2]u16) void {
29 _ = x;
30}
31
32export fn entry6() void {
33 const slice: [:0]const u16 = &.{ 1, 2, 3 };
34 bar(slice);
35}
36
37export fn entry7() void {
38 const slice: [:1]const u16 = &.{ 1, 2 };
39 bar(slice);
40}
41
42export fn entry8() void {
43 const slice: []const u16 = &.{ 1, 2 };
44 bar(slice);
45}
46
47fn bar(x: *const [2:0]u16) void {
48 _ = x;
49}
50
51// error
52//
53// :4:9: error: coercion from slice to array pointer type '*const [2]u16' requires length to be known at compile-time
54// :9:9: error: slice with undefined length cannot cast into array pointer type '*const [2]u16'
55// :9:9: note: length of slice must be defined and match length of array type
56// :15:9: error: slice with undefined length cannot cast into array pointer type '*const [2]u16'
57// :15:9: note: length of slice must be defined and match length of array type
58// :20:9: error: slice of length 3 cannot cast into array pointer type '*const [2]u16'
59// :20:9: note: length of slice must match length of array type
60// :25:9: error: expected type '*const [2]u16', found '[]const u8'
61// :25:9: note: pointer type child 'u8' cannot cast into pointer type child 'u16'
62// :28:11: note: parameter type declared here
63// :34:9: error: slice of length 3 cannot cast into array pointer type '*const [2:0]u16'
64// :34:9: note: length of slice must match length of array type
65// :39:9: error: expected type '*const [2:0]u16', found '[:1]const u16'
66// :39:9: note: pointer sentinel '1' cannot cast into pointer sentinel '0'
67// :47:11: note: parameter type declared here
68// :44:9: error: expected type '*const [2:0]u16', found '[]const u16'
69// :44:9: note: destination pointer requires '0' sentinel
70// :47:11: note: parameter type declared here