Skip to content

Commit

Permalink
parser: fix regression for v -e "import os; import math;", add a te…
Browse files Browse the repository at this point in the history
…st to check it (#19353)
  • Loading branch information
spytheman authored Sep 15, 2023
1 parent 6f61d8b commit 24cb98d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/tools/vtest-all.v
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions vlib/v/parser/parser.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions vlib/v/slow_tests/inout/oneliner_with_semicolons.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
true
1
1.0
1 change: 1 addition & 0 deletions vlib/v/slow_tests/inout/oneliner_with_semicolons.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import os; import math; println(os.getenv('VEXE').len > 2); println(os.args.len); println(math.sin(math.pi / 2));

0 comments on commit 24cb98d

Please sign in to comment.