v.parser: fix error on empty name expr (#10860)

pull/10863/head
Daniel Däschle 2021-07-19 16:09:51 +02:00 committed by GitHub
parent 425ca5e3c3
commit 9127e202d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View File

@ -2093,7 +2093,7 @@ pub fn (mut p Parser) name_expr() ast.Expr {
// if name in ast.builtin_type_names {
if (!known_var && (name in p.table.type_idxs || name_w_mod in p.table.type_idxs)
&& name !in ['C.stat', 'C.sigaction']) || is_mod_cast || is_generic_cast
|| (language == .v && name[0].is_capital()) {
|| (language == .v && name.len > 0 && name[0].is_capital()) {
// MainLetter(x) is *always* a cast, as long as it is not `C.`
// TODO handle C.stat()
start_pos := p.tok.position()

View File

@ -0,0 +1,5 @@
vlib/v/parser/tests/empty_name_expr_err.vv:2:9: error: unexpected name `n`
1 | fn main() {
2 | return n ?(
| ^
3 | }

View File

@ -0,0 +1,3 @@
fn main() {
return n ?(
}