1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: separate SelectorExpr if name is on another line (#7700)

This commit is contained in:
Ned Palacios 2020-12-31 19:37:11 +08:00 committed by GitHub
parent b2bd2c9337
commit 5597925d58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,7 +67,7 @@ mut:
vet_errors []string
cur_fn_name string
in_generic_params bool // indicates if parsing between `<` and `>` of a method/function
name_error bool
name_error bool // indicates if the token is not a name or the name is on another line
}
// for tests
@ -406,6 +406,7 @@ fn (mut p Parser) next() {
}
fn (mut p Parser) check(expected token.Kind) {
p.name_error = false
// for p.tok.kind in [.line_comment, .mline_comment] {
// p.next()
// }
@ -1407,7 +1408,13 @@ fn (mut p Parser) dot_expr(left ast.Expr) ast.Expr {
return p.comptime_method_call(left)
}
name_pos := p.tok.position()
field_name := p.check_name()
mut field_name := ''
// check if the name is on the same line as the dot
if (p.prev_tok.position().line_nr == name_pos.line_nr) || p.tok.kind != .name {
field_name = p.check_name()
} else {
p.name_error = true
}
is_filter := field_name in ['filter', 'map']
if is_filter {
p.open_scope()