From 48ab08c20608c896cf7d60090437112d5aeb0cf6 Mon Sep 17 00:00:00 2001 From: yuyi Date: Sat, 13 Jul 2024 05:08:52 +0800 Subject: [PATCH] vrepl: fix infix shift operation (#21855) --- cmd/tools/vrepl.v | 17 ++++++++--------- .../repl/error_and_continue_print.repl | 6 +++--- vlib/v/slow_tests/repl/error_exitasdfasdf.repl | 6 +++--- vlib/v/slow_tests/repl/infix_shift_op.repl | 17 +++++++++++++++++ 4 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 vlib/v/slow_tests/repl/infix_shift_op.repl diff --git a/cmd/tools/vrepl.v b/cmd/tools/vrepl.v index 458b2da83c..a79fb671a8 100644 --- a/cmd/tools/vrepl.v +++ b/cmd/tools/vrepl.v @@ -39,7 +39,6 @@ const repl_folder = os.join_path(os.vtmp_dir(), 'repl') const possible_statement_patterns = [ '++', '--', - '<<', '//', '/*', 'assert ', @@ -461,19 +460,19 @@ fn run_repl(workdir string, vrepl_prefix string) int { is_statement = true } if !is_statement && (!func_call || fntype == FnType.fn_type) && r.line != '' { - temp_line = 'println(${r.line})' - source_code := r.current_source_code(false, false) + '\n${temp_line}\n' + print_line := 'println(${r.line})' + source_code := r.current_source_code(false, false) + '\n${print_line}\n' os.write_file(temp_file, source_code) or { panic(err) } s := repl_run_vfile(temp_file) or { return 1 } - if s.output.len > r.last_output.len { - cur_line_output := s.output[r.last_output.len..] - print_output(cur_line_output) - if s.exit_code == 0 { + if s.exit_code == 0 { + if s.output.len > r.last_output.len { + cur_line_output := s.output[r.last_output.len..] + print_output(cur_line_output) r.last_output = s.output.clone() - r.lines << temp_line + r.lines << print_line } + continue } - continue } mut temp_source_code := '' if temp_line.starts_with('import ') { diff --git a/vlib/v/slow_tests/repl/error_and_continue_print.repl b/vlib/v/slow_tests/repl/error_and_continue_print.repl index 3cfc0bfbf6..579805c9c8 100644 --- a/vlib/v/slow_tests/repl/error_and_continue_print.repl +++ b/vlib/v/slow_tests/repl/error_and_continue_print.repl @@ -7,9 +7,9 @@ error: undefined ident: `a` (use `:=` to declare a variable) 6 | 7 | a = 3 | ^ -error: undefined ident: `b` +error: `b` evaluated but not used 5 | import math 6 | - 7 | println(b) - | ^ + 7 | b + | ^ [4] diff --git a/vlib/v/slow_tests/repl/error_exitasdfasdf.repl b/vlib/v/slow_tests/repl/error_exitasdfasdf.repl index a026a8ee1a..17abea446d 100644 --- a/vlib/v/slow_tests/repl/error_exitasdfasdf.repl +++ b/vlib/v/slow_tests/repl/error_exitasdfasdf.repl @@ -1,7 +1,7 @@ exitasdfasdf ===output=== -error: undefined ident: `exitasdfasdf` +error: `exitasdfasdf` evaluated but not used 5 | import math 6 | - 7 | println(exitasdfasdf) - | ~~~~~~~~~~~~ + 7 | exitasdfasdf + | ~~~~~~~~~~~~ diff --git a/vlib/v/slow_tests/repl/infix_shift_op.repl b/vlib/v/slow_tests/repl/infix_shift_op.repl new file mode 100644 index 0000000000..561ced11d5 --- /dev/null +++ b/vlib/v/slow_tests/repl/infix_shift_op.repl @@ -0,0 +1,17 @@ +4 >> 1 +4 << 1 +println(4 >> 1) +println(4 << 1) +typeof(4 >> 1).name +typeof(4 << 1).name +println(typeof(4 >> 1).name) +println(typeof(4 << 1).name) +===output=== +2 +8 +2 +8 +int literal +int literal +int literal +int literal