vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.5k stars 2.15k forks source link

checker: add error for `field [$d('x', 2)]int = [1, 2]!` #21741

Closed larpon closed 2 days ago

larpon commented 2 days ago

Add this:

vlib/v/checker/tests/struct_field_fixed_size_init_with_d_as_size_err.vv:3:31: error: cannot initialize a fixed size array field that uses `$d()` as size quantifier since the size may change via -d
    1 | struct Gin {
    2 | mut:
    3 |     juice [$d('amount', 4)]int = [1, 2, 3, 4]!
      |                                  ~~~~~~~~~~~~~
    4 | }
    5 |

for this code:

struct Gin {
mut:
    juice [$d('amount', 4)]int = [1, 2, 3, 4]!
}

fn main() {}