parser: check using invalid keyword with none ident (#13743)
							parent
							
								
									78b1cbefff
								
							
						
					
					
						commit
						1d83ab6be1
					
				|  | @ -1943,6 +1943,7 @@ pub fn (mut p Parser) parse_ident(language ast.Language) ast.Ident { | |||
| 		p.register_auto_import('sync') | ||||
| 	} | ||||
| 	mut_pos := p.tok.pos() | ||||
| 	kind_name := '$p.tok.kind' | ||||
| 	is_mut := p.tok.kind == .key_mut || is_shared || is_atomic | ||||
| 	if is_mut { | ||||
| 		p.next() | ||||
|  | @ -1956,7 +1957,11 @@ pub fn (mut p Parser) parse_ident(language ast.Language) ast.Ident { | |||
| 		p.next() | ||||
| 	} | ||||
| 	if p.tok.kind != .name { | ||||
| 		p.error('unexpected token `$p.tok.lit`') | ||||
| 		if is_mut || is_static || is_volatile { | ||||
| 			p.error_with_pos('the `$kind_name` keyword is invalid here', mut_pos) | ||||
| 		} else { | ||||
| 			p.error('unexpected token `$p.tok.lit`') | ||||
| 		} | ||||
| 		return ast.Ident{ | ||||
| 			scope: p.scope | ||||
| 		} | ||||
|  |  | |||
|  | @ -0,0 +1,6 @@ | |||
| vlib/v/parser/tests/invalid_using_atomic.vv:2:5: error: the `atomic` keyword is invalid here | ||||
|     1 | fn main() { | ||||
|     2 |     if atomic true { | ||||
|       |        ~~~~~~ | ||||
|     3 |         println(true) | ||||
|     4 |     } | ||||
|  | @ -0,0 +1,5 @@ | |||
| fn main() { | ||||
| 	if atomic true { | ||||
| 		println(true) | ||||
| 	} | ||||
| } | ||||
|  | @ -0,0 +1,6 @@ | |||
| vlib/v/parser/tests/invalid_using_mut.vv:2:5: error: the `mut` keyword is invalid here | ||||
|     1 | fn main() { | ||||
|     2 |     if mut true { | ||||
|       |        ~~~ | ||||
|     3 |         println(true) | ||||
|     4 |     } | ||||
|  | @ -0,0 +1,6 @@ | |||
| vlib/v/parser/tests/invalid_using_shared.vv:2:5: error: the `shared` keyword is invalid here | ||||
|     1 | fn main() { | ||||
|     2 |     if shared true { | ||||
|       |        ~~~~~~ | ||||
|     3 |         println(true) | ||||
|     4 |     } | ||||
|  | @ -0,0 +1,5 @@ | |||
| fn main() { | ||||
| 	if shared true { | ||||
| 		println(true) | ||||
| 	} | ||||
| } | ||||
|  | @ -0,0 +1,6 @@ | |||
| vlib/v/parser/tests/invalid_using_static.vv:2:5: error: the `static` keyword is invalid here | ||||
|     1 | fn main() { | ||||
|     2 |     if static true { | ||||
|       |        ~~~~~~ | ||||
|     3 |         println(true) | ||||
|     4 |     } | ||||
|  | @ -0,0 +1,5 @@ | |||
| fn main() { | ||||
| 	if static true { | ||||
| 		println(true) | ||||
| 	} | ||||
| } | ||||
|  | @ -0,0 +1,6 @@ | |||
| vlib/v/parser/tests/invalid_using_volatile.vv:2:5: error: the `volatile` keyword is invalid here | ||||
|     1 | fn main() { | ||||
|     2 |     if volatile true { | ||||
|       |        ~~~~~~~~ | ||||
|     3 |         println(true) | ||||
|     4 |     } | ||||
|  | @ -0,0 +1,5 @@ | |||
| fn main() { | ||||
| 	if volatile true { | ||||
| 		println(true) | ||||
| 	} | ||||
| } | ||||
|  | @ -1,6 +0,0 @@ | |||
| vlib/v/parser/tests/unnecessary_mut_2.vv:2:9: error: unexpected token `true` | ||||
|     1 | fn main() { | ||||
|     2 |     if mut true { | ||||
|       |            ~~~~ | ||||
|     3 |         println(true) | ||||
|     4 |     } | ||||
		Loading…
	
		Reference in New Issue