diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index cc907b451cf00a..5f2496f817651f 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -2683,10 +2683,9 @@ fn (mut p Parser) name_expr() ast.Expr { is_generic_call := p.is_generic_call() is_generic_cast := p.is_generic_cast() is_generic_struct_init := p.is_generic_struct_init() - // p.warn('name expr $p.tok.lit $p.peek_tok.str()') - same_line := p.tok.line_nr == p.peek_tok.line_nr - // `(` must be on same line as name token otherwise it's a ParExpr - if !same_line && p.peek_tok.kind == .lpar { + if p.peek_tok.kind == .lpar && p.tok.line_nr != p.peek_tok.line_nr + && p.peek_token(2).is_next_to(p.peek_tok) { + // `(` must be on same line as name token otherwise it's a ParExpr ident := p.ident(language) node = ident p.add_defer_var(ident) diff --git a/vlib/v/tests/fn_call_with_newline_opening_brace_test.v b/vlib/v/tests/fn_call_with_newline_opening_brace_test.v new file mode 100644 index 00000000000000..f29825dc4b5a74 --- /dev/null +++ b/vlib/v/tests/fn_call_with_newline_opening_brace_test.v @@ -0,0 +1,51 @@ +// vfmt off +struct Address +{ + pub: + street string + city string + state string + zip int +} + +fn test_fn_call_with_newline_opening_brace() +{ + println(initialized_address) + assert true +} + +struct AddressConfig { +pub: + + street string = '1234 Default St' + city string = 'Your Favorite City' + state string = 'Could Be Any' + zip int = 42 +} + +fn new_address(cfg AddressConfig) &Address +{ + return &Address + { + street:cfg.street + city:cfg.city + state:cfg.state + zip:cfg.zip + } +} + +const ( + default_address = new_address(AddressConfig{}) + initialized_address = new_address + ( + street: '0987 tluafeD tS' + city: 'ytiC etirovaF rouY' + state: 'ynA eB dluoC' + zip: 24 + ) +) + +fn (a Address) str() string { + return 'Address.str(): $a.street, $a.city, $a.state $a.zip' +} +// vfmt on