Skip to content

Commit

Permalink
parser: fix fn call with newline opening brace
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Dec 25, 2023
1 parent c7ce72f commit e189e22
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
7 changes: 3 additions & 4 deletions vlib/v/parser/parser.v
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
51 changes: 51 additions & 0 deletions vlib/v/tests/fn_call_with_newline_opening_brace_test.v
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e189e22

Please sign in to comment.