From 085a09ebdbf20a7dcce4b43c45245fc5aec6121f Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 17 Sep 2022 20:58:53 +0800 Subject: [PATCH] vrepl: fix output error of print and fn call (#15796) --- cmd/tools/vrepl.v | 10 ++++++++-- vlib/v/tests/repl/print_and_fn_call.repl | 10 ++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 vlib/v/tests/repl/print_and_fn_call.repl diff --git a/cmd/tools/vrepl.v b/cmd/tools/vrepl.v index b107ef7dcd..aa92f4ad90 100644 --- a/cmd/tools/vrepl.v +++ b/cmd/tools/vrepl.v @@ -390,7 +390,10 @@ fn run_repl(workdir string, vrepl_prefix string) int { source_code := r.current_source_code(false, false) + '\n$r.line\n' os.write_file(temp_file, source_code) or { panic(err) } s := repl_run_vfile(temp_file) or { return 1 } - print_output(s.output) + if s.output.len > r.last_output.len { + cur_line_output := s.output[r.last_output.len..] + print_output(cur_line_output) + } } else { mut temp_line := r.line func_call, fntype := r.function_call(r.line) @@ -441,7 +444,10 @@ fn run_repl(workdir string, vrepl_prefix string) int { source_code := r.current_source_code(false, false) + '\n$temp_line\n' os.write_file(temp_file, source_code) or { panic(err) } s := repl_run_vfile(temp_file) or { return 1 } - print_output(s.output) + if s.output.len > r.last_output.len { + cur_line_output := s.output[r.last_output.len..] + print_output(cur_line_output) + } continue } mut temp_source_code := '' diff --git a/vlib/v/tests/repl/print_and_fn_call.repl b/vlib/v/tests/repl/print_and_fn_call.repl new file mode 100644 index 0000000000..5e02ef33c7 --- /dev/null +++ b/vlib/v/tests/repl/print_and_fn_call.repl @@ -0,0 +1,10 @@ +println('hello') +fn abc(x int) { println(x) } +abc(123) +abc(456) +println('hello') +===output=== +hello +123 +456 +hello