mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: require params
attribute to use struct as keyword arguments in function (#11135)
This commit is contained in:
parent
ae41d1d3c6
commit
b63ec8fbcf
@ -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
|
||||
|
@ -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
|
||||
|
@ -97,6 +97,7 @@ pub fn integer_from_u64(value u64) Integer {
|
||||
}
|
||||
}
|
||||
|
||||
[params]
|
||||
pub struct IntegerConfig {
|
||||
signum int = 1
|
||||
}
|
||||
|
@ -533,6 +533,7 @@ pub fn (h Header) keys() []string {
|
||||
return h.data.keys()
|
||||
}
|
||||
|
||||
[params]
|
||||
pub struct HeaderRenderConfig {
|
||||
version Version
|
||||
coerce bool
|
||||
|
@ -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)
|
||||
|
@ -3,6 +3,7 @@
|
||||
// that can be found in the LICENSE file.
|
||||
module time
|
||||
|
||||
[params]
|
||||
pub struct StopWatchOptions {
|
||||
auto_start bool = true
|
||||
}
|
||||
|
@ -352,6 +352,7 @@ pub fn (t &Table) type_find_method(s &TypeSymbol, name string) ?Fn {
|
||||
return none
|
||||
}
|
||||
|
||||
[params]
|
||||
pub struct GetEmbedsOptions {
|
||||
preceding []Type
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -14,6 +14,7 @@ mut:
|
||||
max_type_len int
|
||||
}
|
||||
|
||||
[params]
|
||||
struct AddInfoConfig {
|
||||
use_threshold bool
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ pub fn (mut f Fmt) attrs(attrs []ast.Attr) {
|
||||
}
|
||||
}
|
||||
|
||||
[params]
|
||||
pub struct AttrsOptions {
|
||||
inline bool
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -1,3 +1,4 @@
|
||||
[params]
|
||||
struct Data {
|
||||
array []int
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -247,6 +247,7 @@ fn test_fixed_field() {
|
||||
//}
|
||||
}
|
||||
*/
|
||||
[params]
|
||||
struct Config {
|
||||
mut:
|
||||
n int
|
||||
|
Loading…
Reference in New Issue
Block a user