Skip to content

parser: change warn to error for const name with upper letter (fix #18838) - #18840

Merged
spytheman merged 3 commits into
vlang:masterfrom
yuyi98:error_wrong_const_name
Jul 11, 2023
Merged

spytheman merged 3 commits into
vlang:masterfrom
yuyi98:error_wrong_const_name

Conversation

@yuyi98

@yuyi98 yuyi98 commented Jul 11, 2023 •

Copy link
Copy Markdown
Member

This PR change warn to error for const name with upper letter (fix #18838).

  • Change warn to error for const name with upper letter.
  • Modify the test.
const CMB_CONJUNTO_QT_DE_BOLAS = 10

fn main() {
	qt_bolas_selecionadas := 1
	
	if qt_bolas_selecionadas == CMB_CONJUNTO_QT_DE_BOLAS {		
		for id := 0; id < 100; id += 1  {
			println("valor: ${id}")
		}
	}	

	if qt_bolas_selecionadas == CMB_CONJUNTO_QT_DE_BOLAS {
		for id := 0; id < 100; id += 1  {
			println("valor: ${id}")
		}
	}	
}

PS D:\Test\v\tt1> v run .
tt1.v:1:7: error: const names cannot contain uppercase letters, use snake_case instead
    1 | const CMB_CONJUNTO_QT_DE_BOLAS = 10
      |       ~~~~~~~~~~~~~~~~~~~~~~~~
    2 | 
    3 | fn main() {

Comment thread vlib/v/parser/parser.v Outdated
@@ -3690,7 +3690,7 @@ fn (mut p Parser) const_decl() ast.ConstDecl {
name := p.check_name()
end_comments << p.eat_comments()
if util.contains_capital(name) {

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.

Suggested change
if util.contains_capital(name) {
if !p.is_translated && util.contains_capital(name) {

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.

The doom code has [translated] on its module xyz statements, and !p.is_translated will silence that error for such code.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok, Thanks !!!

@spytheman
spytheman merged commit 045adb6 into vlang:master Jul 11, 2023
@yuyi98
yuyi98 deleted the error_wrong_const_name branch July 12, 2023 01:07
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.

error: invalid expression: unexpected keyword for

2 participants