parser: improve the error message for unexpected keywords
							parent
							
								
									444d49da75
								
							
						
					
					
						commit
						a5b10b5539
					
				|  | @ -425,7 +425,8 @@ fn (mut p Parser) check(expected token.Kind) { | |||
| 		if expected == .name { | ||||
| 			p.name_error = true | ||||
| 		} | ||||
| 		p.error('unexpected `$p.tok.kind.str()`, expecting `$expected.str()`') | ||||
| 		label := if token.is_key(p.tok.lit) { 'keyword ' } else { '' } | ||||
| 		p.error('unexpected $label`$p.tok.kind.str()`, expecting `$expected.str()`') | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -0,0 +1,7 @@ | |||
| vlib/v/parser/tests/unexpected_keyword.vv:5:12: error: unexpected keyword `import`, expecting `(` | ||||
|     3 | } | ||||
|     4 |  | ||||
|     5 | fn (s Abc) import(name string) { | ||||
|       |            ~~~~~~ | ||||
|     6 |     println(name) | ||||
|     7 | } | ||||
|  | @ -0,0 +1,12 @@ | |||
| struct Abc { | ||||
| 	x int | ||||
| } | ||||
| 
 | ||||
| fn (s Abc) import(name string) { | ||||
| 	println(name) | ||||
| } | ||||
| 
 | ||||
| fn main() { | ||||
| 	s := Abc{} | ||||
| 	s.import('lib') | ||||
| } | ||||
		Loading…
	
		Reference in New Issue