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: fix enum field name same as keyword (fix #22455) #22456

Merged
merged 1 commit into from
Oct 9, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Oct 9, 2024

This PR fix enum field name same as keyword (fix #22455).

  • Fix enum field name same as keyword.
  • Add test.
enum TypeKind {
	none
	const
	enum
	struct
	interface
	sum_type
	i32
	f64
}

fn type_kind(kind TypeKind) string {
	return '${kind}'
}

fn main() {
	mut ret := type_kind(TypeKind.none)
	println(ret)
	assert ret == 'none'

	ret = type_kind(TypeKind.struct)
	println(ret)
	assert ret == 'struct'
}

PS D:\Test\v\tt1> v run .
none
struct

Comment on lines +2 to +9
none
const
enum
struct
interface
sum_type
i32
f64
Copy link
Member

Choose a reason for hiding this comment

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

Afaik prefixing with @, i.e. @none, @const etc is intended for that purpose.

Copy link
Member Author

@yuyi98 yuyi98 Oct 9, 2024

Choose a reason for hiding this comment

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

This is not necessary for enum field name.
Because of a spate of antipathy .struct_ / .interface_ / .enum_ / .none_ , inconsistent with other style, I think its processing style, instead of .struct / .interface / .enum / .none .

Copy link
Member

Choose a reason for hiding this comment

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

I do not know then.
@medvednikov what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I like it. Great job!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is asking for problems, rather than helping anything. For the same reason V doesn't allow both .. and ... in ranges, is it too easy to visually confuse struct with .struct, etc. Especially in certain fonts.

@spytheman spytheman merged commit 4c82b01 into vlang:master Oct 9, 2024
78 checks passed
@yuyi98 yuyi98 deleted the fix_enum_keyword_field_name branch October 10, 2024 01:06
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.

Enum field name error: unexpected keyword none, expecting name
4 participants