From 0b750a234f6968f67690ccecdfc0f3a6518ee374 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 3 May 2020 20:48:46 +0300 Subject: [PATCH] repl: fix for single lines ending with // comment --- vlib/v/scanner/scanner.v | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index c3d38c8002..0c6ffb0c83 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -76,12 +76,14 @@ pub fn new_scanner(text string, comments_mode CommentsMode) &Scanner { } pub fn (s &Scanner) add_fn_main_and_rescan(pos int) { + // NB: the text may have ended in // comment, which would hide the ending } + // To avoid that, we need a \n right before it. if pos > 0 { - s.text = s.text[..pos] + 'fn main() {' + s.text[pos..] + '}' + s.text = s.text[..pos] + 'fn main() {' + s.text[pos..] + '\n}' s.pos = pos s.is_started = false } else { - s.text = 'fn main() {' + s.text + '}' + s.text = 'fn main() {' + s.text + '\n}' s.pos = 0 s.line_nr = 0 s.is_started = false