Skip to content

Commit 085a09e

Browse files
authored
vrepl: fix output error of print and fn call (#15796)
1 parent afe7166 commit 085a09e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

cmd/tools/vrepl.v

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,10 @@ fn run_repl(workdir string, vrepl_prefix string) int {
390390
source_code := r.current_source_code(false, false) + '\n$r.line\n'
391391
os.write_file(temp_file, source_code) or { panic(err) }
392392
s := repl_run_vfile(temp_file) or { return 1 }
393-
print_output(s.output)
393+
if s.output.len > r.last_output.len {
394+
cur_line_output := s.output[r.last_output.len..]
395+
print_output(cur_line_output)
396+
}
394397
} else {
395398
mut temp_line := r.line
396399
func_call, fntype := r.function_call(r.line)
@@ -441,7 +444,10 @@ fn run_repl(workdir string, vrepl_prefix string) int {
441444
source_code := r.current_source_code(false, false) + '\n$temp_line\n'
442445
os.write_file(temp_file, source_code) or { panic(err) }
443446
s := repl_run_vfile(temp_file) or { return 1 }
444-
print_output(s.output)
447+
if s.output.len > r.last_output.len {
448+
cur_line_output := s.output[r.last_output.len..]
449+
print_output(cur_line_output)
450+
}
445451
continue
446452
}
447453
mut temp_source_code := ''
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
println('hello')
2+
fn abc(x int) { println(x) }
3+
abc(123)
4+
abc(456)
5+
println('hello')
6+
===output===
7+
hello
8+
123
9+
456
10+
hello

0 commit comments

Comments
 (0)