From a9bb6865fd12d7dfedaaee3c71d294dcce937536 Mon Sep 17 00:00:00 2001 From: yuyi Date: Mon, 3 Apr 2023 19:37:52 +0800 Subject: [PATCH] scanner: fix checking comments not terminated (fix #17842) (#17855) --- vlib/v/scanner/scanner.v | 6 +++--- vlib/v/scanner/tests/comments_not_terminated_err.out | 7 +++++++ vlib/v/scanner/tests/comments_not_terminated_err.vv | 7 +++++++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 vlib/v/scanner/tests/comments_not_terminated_err.out create mode 100644 vlib/v/scanner/tests/comments_not_terminated_err.vv diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index 3898945d43..03e754c59e 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -1063,9 +1063,9 @@ fn (mut s Scanner) text_scan() token.Token { // Skip comment for nest_count > 0 && s.pos < s.text.len - 1 { s.pos++ - if s.pos >= s.text.len { - s.line_nr-- - s.error('comment not terminated') + if s.pos >= s.text.len - 1 { + s.line_nr = start_line + s.error('unterminated multiline comment') } if s.text[s.pos] == scanner.b_lf { s.inc_line_number() diff --git a/vlib/v/scanner/tests/comments_not_terminated_err.out b/vlib/v/scanner/tests/comments_not_terminated_err.out new file mode 100644 index 0000000000..de4f471840 --- /dev/null +++ b/vlib/v/scanner/tests/comments_not_terminated_err.out @@ -0,0 +1,7 @@ +vlib/v/scanner/tests/comments_not_terminated_err.vv:5:2: error: unterminated multiline comment + 3 | } + 4 | + 5 | /* + | ^ + 6 | fn tt() { + 7 | } diff --git a/vlib/v/scanner/tests/comments_not_terminated_err.vv b/vlib/v/scanner/tests/comments_not_terminated_err.vv new file mode 100644 index 0000000000..785173fcd0 --- /dev/null +++ b/vlib/v/scanner/tests/comments_not_terminated_err.vv @@ -0,0 +1,7 @@ +fn main() { + println('hello, world') +} + +/* +fn tt() { +}