Skip to content

parser: fix fn call with newline opening brace (fix #20258) - #20267

Merged
spytheman merged 3 commits into
vlang:masterfrom
yuyi98:fix_parser_call_expr
Dec 25, 2023
Merged

spytheman merged 3 commits into
vlang:masterfrom
yuyi98:fix_parser_call_expr

Conversation

@yuyi98

@yuyi98 yuyi98 commented Dec 25, 2023

Copy link
Copy Markdown
Member

This PR fix fn call with newline opening brace (fix #20258).

  • Fix fn call with newline opening brace.
  • Add test.
// vfmt off
struct Address
{
	pub:
		street string
		city string
		state string
		zip int
}

fn main() 
{
	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

PS D:\Test\v\tt1> v run .
&Address.str(): 0987 tluafeD tS, ytiC etirovaF rouY, ynA eB dluoC 24

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman
spytheman merged commit 113da28 into vlang:master Dec 25, 2023
@yuyi98
yuyi98 deleted the fix_parser_call_expr branch December 26, 2023 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

function return struct opening brace produce compiler time error

2 participants