parser: fix regression for v -e "import os; import math;", add a test to check it (#19353)

This commit is contained in:
Delyan Angelov 2023-09-15 09:59:05 +03:00 committed by GitHub
parent 6f61d8ba78
commit 24cb98d5dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 0 deletions

View File

@ -101,6 +101,12 @@ fn get_all_commands() []Command {
runcmd: .execute
expect: '42'
}
res << Command{
line: '${vexe} -e "import os; import math; print(os.args#[1..]) print(math.sin(math.pi/2).str())" arg1 arg2'
okmsg: 'V can run code with `-e`, that use semicolons and several imports, and that accepts CLI parameters.'
runcmd: .execute
expect: "['arg1', 'arg2']1.0"
}
$if linux || macos {
res << Command{
line: '${vexe} run examples/hello_world.v'

View File

@ -3666,6 +3666,9 @@ fn (mut p Parser) import_stmt() ast.Import {
import_node.comments = p.eat_comments(same_line: true)
import_node.next_comments = p.eat_comments(follow_up: true)
p.imports[mod_alias] = mod_name
if p.tok.kind == .semicolon {
p.check(.semicolon)
}
// if mod_name !in p.table.imports {
p.table.imports << mod_name
p.ast_imports << import_node

View File

@ -0,0 +1,3 @@
true
1
1.0

View File

@ -0,0 +1 @@
import os; import math; println(os.getenv('VEXE').len > 2); println(os.args.len); println(math.sin(math.pi / 2));