From e512caf8f57f947113e603310077c00da2faaae2 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 22 May 2021 16:42:38 +0300 Subject: [PATCH] vfmt: do not error on `field [fsize]Type`, where `fsize` is from another .v file --- vlib/v/fmt/tests/fixed_size_array_type_keep.vv | 14 ++++++++++++++ vlib/v/parser/parse_type.v | 9 ++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/vlib/v/fmt/tests/fixed_size_array_type_keep.vv b/vlib/v/fmt/tests/fixed_size_array_type_keep.vv index 31639b3245..fbe0001a14 100644 --- a/vlib/v/fmt/tests/fixed_size_array_type_keep.vv +++ b/vlib/v/fmt/tests/fixed_size_array_type_keep.vv @@ -12,3 +12,17 @@ fn foo() [1]f32 { fn main() { _ := [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 +} diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index 357f453104..eb3904ae15 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -26,7 +26,14 @@ pub fn (mut p Parser) parse_array_type() ast.Type { size_expr.pos) } } 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 {