Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser: allow for variable name using keyword 'type' #22512

Merged
merged 2 commits into from
Oct 14, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Oct 13, 2024

This PR allow for variable name using keyword 'type'.

  • Allow for variable name using keyword 'type'.
  • Add test.
fn info(type int) int {
	return type
}

fn print_info() {
	for type in [1, 2, 3] {
		println(type)
	}
}

fn main() {
	ret := info(22)
	println(ret)
	assert ret == 22

	type := 33
	println(type)
	assert type == 33

	print_info()
	assert true
}

PS D:\Test\v\tt1> v run .    
22
33
1
2
3

if p.tok.kind != .eof && !(p.tok.kind == .rsbr && p.inside_asm) {
} else if p.tok.kind == .key_type {
// variable name: type
ident := p.ident(ast.Language.v)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just use .v?

ident := p.ident(.v)

Copy link
Member Author

Choose a reason for hiding this comment

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

It is currently only used in v.

Copy link
Member

Choose a reason for hiding this comment

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

he meant using p.ident(.v) instead of p.ident(ast.Language.v)

indeed that's simpler and I thought vfmt simplified it already

Copy link
Member Author

Choose a reason for hiding this comment

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

I see.
Yes, it can. Thank you!

@medvednikov medvednikov merged commit 7220f75 into vlang:master Oct 14, 2024
78 checks passed
@yuyi98 yuyi98 deleted the allow_var_name_type branch October 15, 2024 01:01
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.

3 participants