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

parser: fix parsing of go call expression (#8138)

This commit is contained in:
Uwe Krüger 2021-01-15 18:47:49 +01:00 committed by GitHub
parent 5de287a6e7
commit 1c6fe83408
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 27 deletions

View File

@ -90,41 +90,21 @@ fn (mut p Parser) partial_assign_stmt(left []ast.Expr, left_comments []ast.Comme
op := p.tok.kind
pos := p.tok.position()
p.next()
mut comments := []ast.Comment{cap: 2 * left_comments.len + 1}
comments << left_comments
comments << p.eat_comments()
mut right_comments := []ast.Comment{}
mut right := []ast.Expr{cap: left.len}
if p.tok.kind == .key_go {
spos := p.tok.position()
p.next()
right_comments = p.eat_comments()
mut mod := ''
mut language := table.Language.v
if p.peek_tok.kind == .dot {
if p.tok.lit == 'C' {
language = table.Language.c
p.check_for_impure_v(language, p.tok.position())
} else if p.tok.lit == 'JS' {
language = table.Language.js
p.check_for_impure_v(language, p.tok.position())
} else {
mod = p.tok.lit
}
p.next()
p.next()
}
call_expr := p.call_expr(language, mod)
allpos := spos.extend(p.tok.position())
stmt := p.stmt(false)
go_stmt := stmt as ast.GoStmt
right << ast.GoExpr{
go_stmt: ast.GoStmt{
call_expr: call_expr
pos: allpos
}
pos: allpos
go_stmt: go_stmt
pos: go_stmt.pos
}
} else {
right, right_comments = p.expr_list()
}
mut comments := []ast.Comment{cap: left_comments.len + right_comments.len}
comments << left_comments
comments << right_comments
end_comments := p.eat_line_end_comments()
mut has_cross_var := false

View File

@ -0,0 +1,22 @@
struct Test {
sub SubTest
}
struct SubTest {
test string
}
fn test_method_go_wait() {
a := Test{
sub: SubTest{
test: 'hi'
}
}
thread := go a.sub.get()
r := thread.wait()
assert r == 'hi'
}
fn (t SubTest) get() string {
return t.test
}