From 35e6a40c0eadacf6825037121a5817c3cff08239 Mon Sep 17 00:00:00 2001 From: yuyi Date: Fri, 5 Jul 2024 17:47:24 +0800 Subject: [PATCH] vrepl: fix variable name starts with print (#21806) --- cmd/tools/vrepl.v | 6 +++--- vlib/v/slow_tests/repl/var_starts_with_print.repl | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 vlib/v/slow_tests/repl/var_starts_with_print.repl diff --git a/cmd/tools/vrepl.v b/cmd/tools/vrepl.v index 80b484338..998f14fe6 100644 --- a/cmd/tools/vrepl.v +++ b/cmd/tools/vrepl.v @@ -384,7 +384,7 @@ fn run_repl(workdir string, vrepl_prefix string) int { r.in_func = true r.functions_name << r.line.all_before(':= fn(').trim_space() } - if r.line.starts_with('fn') { + if r.line.starts_with('fn ') { r.in_func = true r.functions_name << r.line.all_after('fn').all_before('(').trim_space() } @@ -428,7 +428,7 @@ fn run_repl(workdir string, vrepl_prefix string) int { if r.line.starts_with('=') { r.line = 'println(' + r.line[1..] + ')' } - if r.line.starts_with('print') { + if r.line.starts_with('print(') || r.line.starts_with('println(') { 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 } @@ -484,7 +484,7 @@ 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 if temp_line.starts_with('fn') { + } else if temp_line.starts_with('fn ') { temp_source_code = r.current_source_code(false, false) } else { temp_source_code = r.current_source_code(true, false) + '\n${temp_line}\n' diff --git a/vlib/v/slow_tests/repl/var_starts_with_print.repl b/vlib/v/slow_tests/repl/var_starts_with_print.repl new file mode 100644 index 000000000..b4481aa5c --- /dev/null +++ b/vlib/v/slow_tests/repl/var_starts_with_print.repl @@ -0,0 +1,7 @@ +a_variable := "yessir" +a_variable +printme := "ohno" +printme +===output=== +yessir +ohno -- 2.39.5