| 1 | const c_a_s = 1 |
| 2 | const c_b_s = 1 + 1 |
| 3 | const c_c_s = c_b_s + 1 |
| 4 | |
| 5 | fn test_consant_array_size() { |
| 6 | mut a := [c_a_s]int{} |
| 7 | a = [1]! |
| 8 | mut b := [c_b_s]int{} |
| 9 | b = [1, 2]! |
| 10 | } |
| 11 | |
| 12 | // for 19593 |
| 13 | // test const was declared below struct fixed array fields declaration |
| 14 | struct Foo { |
| 15 | arr [width][2][width + 1]f64 |
| 16 | } |
| 17 | |
| 18 | fn test_const_below_at_struct_fixed_array_fields() { |
| 19 | foo := Foo{} |
| 20 | assert foo.arr.len == 2 |
| 21 | assert foo.arr[0].len == 2 |
| 22 | assert foo.arr[0][0].len == 3 |
| 23 | assert foo.arr == [[[0.0, 0.0, 0.0]!, [0.0, 0.0, 0.0]!]!, |
| 24 | [[0.0, 0.0, 0.0]!, [0.0, 0.0, 0.0]!]!]! |
| 25 | } |
| 26 | |
| 27 | // for issue 20311 |
| 28 | // when using a const variable to define a fixed array size, |
| 29 | // if the const variable is defined below or in another module, the size value will not be calculated correctly. |
| 30 | fn test_const_below_at_fixed_array() { |
| 31 | arr := [width][2][width + 1]f64{} |
| 32 | assert arr.len == 2 |
| 33 | assert arr[0].len == 2 |
| 34 | assert arr[0][0].len == 3 |
| 35 | assert arr == [[[0.0, 0.0, 0.0]!, [0.0, 0.0, 0.0]!]!, [[0.0, 0.0, 0.0]!, |
| 36 | [0.0, 0.0, 0.0]!]!]! |
| 37 | } |
| 38 | |
| 39 | // do not move this definition, |
| 40 | // it must be below `struct Foo {...}` and `fn test_const_below_at_fixed_array()`. |
| 41 | const width = 2 |
| 42 | |