Skip to content

Commit 175ede5

Browse files
repl: fix an issue with print and println after the execution of for or if (fix #20524) (#20525)
1 parent fd19458 commit 175ede5

File tree

6 files changed

+21
-37
lines changed

6 files changed

+21
-37
lines changed

cmd/tools/vrepl.v

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -477,23 +477,13 @@ fn run_repl(workdir string, vrepl_prefix string) int {
477477
} else if temp_line.starts_with('#include ') {
478478
temp_source_code = '${temp_line}\n' + r.current_source_code(false, false)
479479
} else {
480-
for i, l in r.lines {
481-
if (l.starts_with('for ') || l.starts_with('if ')) && l.contains('println') {
482-
r.lines.delete(i)
483-
break
484-
}
485-
}
486480
temp_source_code = r.current_source_code(true, false) + '\n${temp_line}\n'
487481
}
488482
os.write_file(temp_file, temp_source_code) or { panic(err) }
489483
s := repl_run_vfile(temp_file) or { return 1 }
490484
if s.exit_code == 0 {
491-
for r.temp_lines.len > 0 {
492-
if !r.temp_lines[0].starts_with('print') {
493-
r.lines << r.temp_lines[0]
494-
}
495-
r.temp_lines.delete(0)
496-
}
485+
r.lines << r.temp_lines
486+
r.temp_lines.clear()
497487
if r.line.starts_with('import ') {
498488
r.parse_import(r.line)
499489
} else if r.line.starts_with('#include ') {
@@ -600,7 +590,7 @@ fn repl_run_vfile(file string) !os.Result {
600590
$if trace_repl_temp_files ? {
601591
eprintln('>> repl_run_vfile file: ${file}')
602592
}
603-
s := os.execute('${os.quoted_path(vexe)} -repl run ${os.quoted_path(file)}')
593+
s := os.execute('${os.quoted_path(vexe)} -message-limit 1 -repl run ${os.quoted_path(file)}')
604594
if s.exit_code < 0 {
605595
rerror(s.output)
606596
return error(s.output)

vlib/v/slow_tests/repl/error.repl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,3 @@ error: undefined ident: `a`
55
6 |
66
7 | println(a)
77
| ^
8-
error: `println` can not print void expressions
9-
5 | import math
10-
6 |
11-
7 | println(a)
12-
| ~~~~~~~~~~

vlib/v/slow_tests/repl/error_and_continue_print.repl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,9 @@ error: undefined ident: `a` (use `:=` to declare a variable)
77
6 |
88
7 | a = 3
99
| ^
10-
error: cannot assign to `a`: expected `void`, not `int literal`
11-
5 | import math
12-
6 |
13-
7 | a = 3
14-
| ^
1510
error: undefined ident: `b`
1611
5 | import math
1712
6 |
1813
7 | println(b)
1914
| ^
20-
error: `println` can not print void expressions
21-
5 | import math
22-
6 |
23-
7 | println(b)
24-
| ~~~~~~~~~~
2515
[4]

vlib/v/slow_tests/repl/error_exitasdfasdf.repl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,3 @@ error: undefined ident: `exitasdfasdf`
55
6 |
66
7 | println(exitasdfasdf)
77
| ~~~~~~~~~~~~
8-
error: `println` can not print void expressions
9-
5 | import math
10-
6 |
11-
7 | println(exitasdfasdf)
12-
| ~~~~~~~~~~~~~~~~~~~~~

vlib/v/slow_tests/repl/function.repl.skip

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
mut numbers := [1,2,3,4,5]
2+
if 1 in numbers {
3+
println('yes')
4+
}
5+
println('hi')
6+
for number in numbers {
7+
println(number)
8+
}
9+
println(numbers)
10+
===output===
11+
yes
12+
hi
13+
1
14+
2
15+
3
16+
4
17+
5
18+
[1, 2, 3, 4, 5]

0 commit comments

Comments
 (0)