Skip to content

Commit

Permalink
repl: fix an issue with print and println after the execution of `f…
Browse files Browse the repository at this point in the history
…or` or `if` (fix #20524) (#20525)
  • Loading branch information
viniciusfdasilva committed Jan 14, 2024
1 parent fd19458 commit 175ede5
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 37 deletions.
16 changes: 3 additions & 13 deletions cmd/tools/vrepl.v
Expand Up @@ -477,23 +477,13 @@ fn run_repl(workdir string, vrepl_prefix string) int {
} else if temp_line.starts_with('#include ') {
temp_source_code = '${temp_line}\n' + r.current_source_code(false, false)
} else {
for i, l in r.lines {
if (l.starts_with('for ') || l.starts_with('if ')) && l.contains('println') {
r.lines.delete(i)
break
}
}
temp_source_code = r.current_source_code(true, false) + '\n${temp_line}\n'
}
os.write_file(temp_file, temp_source_code) or { panic(err) }
s := repl_run_vfile(temp_file) or { return 1 }
if s.exit_code == 0 {
for r.temp_lines.len > 0 {
if !r.temp_lines[0].starts_with('print') {
r.lines << r.temp_lines[0]
}
r.temp_lines.delete(0)
}
r.lines << r.temp_lines
r.temp_lines.clear()
if r.line.starts_with('import ') {
r.parse_import(r.line)
} else if r.line.starts_with('#include ') {
Expand Down Expand Up @@ -600,7 +590,7 @@ fn repl_run_vfile(file string) !os.Result {
$if trace_repl_temp_files ? {
eprintln('>> repl_run_vfile file: ${file}')
}
s := os.execute('${os.quoted_path(vexe)} -repl run ${os.quoted_path(file)}')
s := os.execute('${os.quoted_path(vexe)} -message-limit 1 -repl run ${os.quoted_path(file)}')
if s.exit_code < 0 {
rerror(s.output)
return error(s.output)
Expand Down
5 changes: 0 additions & 5 deletions vlib/v/slow_tests/repl/error.repl
Expand Up @@ -5,8 +5,3 @@ error: undefined ident: `a`
6 |
7 | println(a)
| ^
error: `println` can not print void expressions
5 | import math
6 |
7 | println(a)
| ~~~~~~~~~~
10 changes: 0 additions & 10 deletions vlib/v/slow_tests/repl/error_and_continue_print.repl
Expand Up @@ -7,19 +7,9 @@ error: undefined ident: `a` (use `:=` to declare a variable)
6 |
7 | a = 3
| ^
error: cannot assign to `a`: expected `void`, not `int literal`
5 | import math
6 |
7 | a = 3
| ^
error: undefined ident: `b`
5 | import math
6 |
7 | println(b)
| ^
error: `println` can not print void expressions
5 | import math
6 |
7 | println(b)
| ~~~~~~~~~~
[4]
5 changes: 0 additions & 5 deletions vlib/v/slow_tests/repl/error_exitasdfasdf.repl
Expand Up @@ -5,8 +5,3 @@ error: undefined ident: `exitasdfasdf`
6 |
7 | println(exitasdfasdf)
| ~~~~~~~~~~~~
error: `println` can not print void expressions
5 | import math
6 |
7 | println(exitasdfasdf)
| ~~~~~~~~~~~~~~~~~~~~~
4 changes: 0 additions & 4 deletions vlib/v/slow_tests/repl/function.repl.skip

This file was deleted.

18 changes: 18 additions & 0 deletions vlib/v/slow_tests/repl/if_and_for_with_print_inside_them.repl
@@ -0,0 +1,18 @@
mut numbers := [1,2,3,4,5]
if 1 in numbers {
println('yes')
}
println('hi')
for number in numbers {
println(number)
}
println(numbers)
===output===
yes
hi
1
2
3
4
5
[1, 2, 3, 4, 5]

0 comments on commit 175ede5

Please sign in to comment.