vfmt: do not error on `field [fsize]Type`, where `fsize` is from another .v file

pull/10172/head
Delyan Angelov 2021-05-22 16:42:38 +03:00
parent 7c0f8f7644
commit e512caf8f5
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 22 additions and 1 deletions

View File

@ -12,3 +12,17 @@ fn foo() [1]f32 {
fn main() { fn main() {
_ := [5]string{init: 'abc'} _ := [5]string{init: 'abc'}
} }
// NB: secret_key_size is missing here on purpose
// vfmt should leave it as is, assuming it is comming
// from another .v file
struct VerifyKey {
public_key [public_key_size]byte
}
struct SigningKey {
secret_key [secret_key_size]byte
pub:
verify_key VerifyKey
}

View File

@ -26,7 +26,14 @@ pub fn (mut p Parser) parse_array_type() ast.Type {
size_expr.pos) size_expr.pos)
} }
} else { } else {
p.error_with_pos('non-constant array bound `$size_expr.name`', size_expr.pos) if p.pref.is_fmt {
// for vfmt purposes, pretend the constant does exist, it may have
// been defined in another .v file:
fixed_size = 1
} else {
p.error_with_pos('non-constant array bound `$size_expr.name`',
size_expr.pos)
}
} }
} }
else { else {