diff --git a/vlib/gx/text.v b/vlib/gx/text.v index fee934a07c..986bbc0b48 100644 --- a/vlib/gx/text.v +++ b/vlib/gx/text.v @@ -1,11 +1,12 @@ module gx -// TODO: remove these and uae the enum everywhere +// TODO: remove these, and use the enum everywhere pub const ( align_left = HorizontalAlign.left align_right = HorizontalAlign.right ) +[params] pub struct TextCfg { pub: color Color = black diff --git a/vlib/io/util/util.v b/vlib/io/util/util.v index 6f0d93f516..7aeca1af33 100644 --- a/vlib/io/util/util.v +++ b/vlib/io/util/util.v @@ -8,6 +8,7 @@ const ( retries = 10000 ) +[params] pub struct TempFileOptions { path string = os.temp_dir() pattern string @@ -44,6 +45,7 @@ pub fn temp_file(tfo TempFileOptions) ?(os.File, string) { ' could not create temporary file in "$d". Retry limit ($util.retries) exhausted. Please ensure write permissions.') } +[params] pub struct TempDirOptions { path string = os.temp_dir() pattern string diff --git a/vlib/math/big/integer.v b/vlib/math/big/integer.v index 5cc9fac2ca..fb0f5ef234 100644 --- a/vlib/math/big/integer.v +++ b/vlib/math/big/integer.v @@ -97,6 +97,7 @@ pub fn integer_from_u64(value u64) Integer { } } +[params] pub struct IntegerConfig { signum int = 1 } diff --git a/vlib/net/http/header.v b/vlib/net/http/header.v index c05bdbc091..0e8cb00793 100644 --- a/vlib/net/http/header.v +++ b/vlib/net/http/header.v @@ -533,6 +533,7 @@ pub fn (h Header) keys() []string { return h.data.keys() } +[params] pub struct HeaderRenderConfig { version Version coerce bool diff --git a/vlib/rand/config/config.v b/vlib/rand/config/config.v index b11e77cd6b..9baeeaa0be 100644 --- a/vlib/rand/config/config.v +++ b/vlib/rand/config/config.v @@ -7,6 +7,7 @@ import rand.seed // generator WyRand used 64 bits, ie. 2 u32s so that is the default. In case your desired generator // uses a different number of u32s, use the `seed.time_seed_array()` method with the correct // number of u32s. +[params] pub struct PRNGConfigStruct { pub: seed_ []u32 = seed.time_seed_array(2) diff --git a/vlib/time/stopwatch.v b/vlib/time/stopwatch.v index 569e10c254..049563dc8a 100644 --- a/vlib/time/stopwatch.v +++ b/vlib/time/stopwatch.v @@ -3,6 +3,7 @@ // that can be found in the LICENSE file. module time +[params] pub struct StopWatchOptions { auto_start bool = true } diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index 96fb617bc1..8c11815f16 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -352,6 +352,7 @@ pub fn (t &Table) type_find_method(s &TypeSymbol, name string) ?Fn { return none } +[params] pub struct GetEmbedsOptions { preceding []Type } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 83e36986af..358ae9501d 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -2088,15 +2088,17 @@ pub fn (mut c Checker) check_expected_arg_count(mut node ast.CallExpr, f &ast.Fn if min_required_params == nr_args + 1 { last_typ := f.params.last().typ last_sym := c.table.get_type_symbol(last_typ) - if last_sym.kind == .struct_ { - // allow empty trailing struct syntax arg (`f()` where `f` is `fn(ConfigStruct)`) - node.args << ast.CallArg{ - expr: ast.StructInit{ - typ: last_typ + if last_sym.info is ast.Struct { + is_params := last_sym.info.attrs.filter(it.name == 'params' && !it.has_arg).len > 0 + if is_params { + // allow empty trailing struct syntax arg (`f()` where `f` is `fn(ConfigStruct)`) + node.args << ast.CallArg{ + expr: ast.StructInit{ + typ: last_typ + } } - typ: last_typ + return } - return } } c.error('expected $min_required_params arguments, but got $nr_args', node.pos) diff --git a/vlib/v/fmt/align.v b/vlib/v/fmt/align.v index f767abdb93..47e455cc45 100644 --- a/vlib/v/fmt/align.v +++ b/vlib/v/fmt/align.v @@ -14,6 +14,7 @@ mut: max_type_len int } +[params] struct AddInfoConfig { use_threshold bool } diff --git a/vlib/v/fmt/attrs.v b/vlib/v/fmt/attrs.v index 798cbb2d42..0539d63f67 100644 --- a/vlib/v/fmt/attrs.v +++ b/vlib/v/fmt/attrs.v @@ -18,6 +18,7 @@ pub fn (mut f Fmt) attrs(attrs []ast.Attr) { } } +[params] pub struct AttrsOptions { inline bool } diff --git a/vlib/v/fmt/comments.v b/vlib/v/fmt/comments.v index 8c557943fa..3cb760411b 100644 --- a/vlib/v/fmt/comments.v +++ b/vlib/v/fmt/comments.v @@ -16,6 +16,7 @@ pub enum CommentsLevel { // - level: either .keep (don't indent), or .indent (increment indentation) // - iembed: a /* ... */ block comment used inside expressions; // comments the whole line // - prev_line: the line number of the previous token to save linebreaks +[params] pub struct CommentsOptions { has_nl bool = true inline bool diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 8f4c9082eb..dc1b8c2d90 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -133,6 +133,7 @@ pub fn (mut f Fmt) wrap_long_line(penalty_idx int, add_indent bool) bool { return true } +[params] pub struct RemoveNewLineConfig { imports_buffer bool // Work on f.out_imports instead of f.out } diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index e4180ea59f..827fd4fbb1 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -642,6 +642,7 @@ pub fn (mut p Parser) comment_stmt() ast.ExprStmt { } } +[params] struct EatCommentsConfig { same_line bool // Only eat comments on the same line as the previous token follow_up bool // Comments directly below the previous token as long as there is no empty line diff --git a/vlib/v/tests/match_in_fn_call_test.v b/vlib/v/tests/match_in_fn_call_test.v index eb388e0e10..fcc774c7d1 100644 --- a/vlib/v/tests/match_in_fn_call_test.v +++ b/vlib/v/tests/match_in_fn_call_test.v @@ -1,3 +1,4 @@ +[params] struct Data { array []int } diff --git a/vlib/v/tests/missing_config_struct_arg_test.v b/vlib/v/tests/missing_config_struct_arg_test.v index 0e206bcaab..a4909fee09 100644 --- a/vlib/v/tests/missing_config_struct_arg_test.v +++ b/vlib/v/tests/missing_config_struct_arg_test.v @@ -1,3 +1,4 @@ +[params] struct Foo { x int } @@ -6,6 +7,7 @@ fn foo(f Foo) int { return f.x } +[params] struct Bar { x int y int = 1234 diff --git a/vlib/v/tests/struct_test.v b/vlib/v/tests/struct_test.v index db5a242696..3349c9fe6e 100644 --- a/vlib/v/tests/struct_test.v +++ b/vlib/v/tests/struct_test.v @@ -247,6 +247,7 @@ fn test_fixed_field() { //} } */ +[params] struct Config { mut: n int