v2 / vlib / v / tests / fns / unused_fn_fixed_array_ret_test.v
37 lines · 34 sloc · 897 bytes · 06dd19b7747c08bef4f4fcf582e13445dd0c31f4
Raw
1// Test that unused functions returning fixed arrays of custom structs
2// don't cause C compilation errors when skip_unused is enabled.
3// Related to: functions returning [N]CustomStruct where the function is never called.
4
5struct QuadVertex {
6 pos [2]f32
7 uv [2]f32
8}
9
10// This function is intentionally never called - it tests that skip_unused
11// correctly handles fn_ret ArrayFixed types with custom struct elements.
12pub fn make_quad_vertices(x f32, y f32, w f32, h f32) [4]QuadVertex {
13 return [
14 QuadVertex{
15 pos: [x, y]!
16 uv: [f32(0), 0]!
17 },
18 QuadVertex{
19 pos: [x + w, y]!
20 uv: [f32(1), 0]!
21 },
22 QuadVertex{
23 pos: [x + w, y + h]!
24 uv: [f32(1), 1]!
25 },
26 QuadVertex{
27 pos: [x, y + h]!
28 uv: [f32(0), 1]!
29 },
30 ]!
31}
32
33fn test_unused_fn_fixed_array_ret() {
34 // The test passes if compilation succeeds.
35 // make_quad_vertices is intentionally not called.
36 assert true
37}
38