diff --git a/vlib/v/checker/tests/.gitattributes b/vlib/v/checker/tests/.gitattributes new file mode 100644 index 0000000000..20f8e01d86 --- /dev/null +++ b/vlib/v/checker/tests/.gitattributes @@ -0,0 +1,2 @@ +*_crlf_* binary +*_lf_* binary diff --git a/vlib/v/checker/tests/error_with_comment_with_crlf_ending.out b/vlib/v/checker/tests/error_with_comment_with_crlf_ending.out new file mode 100644 index 0000000000..5e4630e384 --- /dev/null +++ b/vlib/v/checker/tests/error_with_comment_with_crlf_ending.out @@ -0,0 +1,4 @@ +vlib/v/checker/tests/error_with_comment_with_crlf_ending.vv:2:6: error: unexpected name `should` + 1 | // Empty lines don't cause an issue but as soon as there's a comment with a CRLF ending, it fails + 2 | This should cause an error! + | ~~~~~~ diff --git a/vlib/v/checker/tests/error_with_comment_with_crlf_ending.vv b/vlib/v/checker/tests/error_with_comment_with_crlf_ending.vv new file mode 100644 index 0000000000..256462ac08 --- /dev/null +++ b/vlib/v/checker/tests/error_with_comment_with_crlf_ending.vv @@ -0,0 +1,2 @@ +// Empty lines don't cause an issue but as soon as there's a comment with a CRLF ending, it fails +This should cause an error! \ No newline at end of file diff --git a/vlib/v/checker/tests/error_with_comment_with_lf_ending.out b/vlib/v/checker/tests/error_with_comment_with_lf_ending.out new file mode 100644 index 0000000000..fcf35240d1 --- /dev/null +++ b/vlib/v/checker/tests/error_with_comment_with_lf_ending.out @@ -0,0 +1,4 @@ +vlib/v/checker/tests/error_with_comment_with_lf_ending.vv:2:6: error: unexpected name `should` + 1 | // Empty lines don't cause an issue but as soon as there's a comment with a CRLF ending, it fails + 2 | This should cause an error! + | ~~~~~~ diff --git a/vlib/v/checker/tests/error_with_comment_with_lf_ending.vv b/vlib/v/checker/tests/error_with_comment_with_lf_ending.vv new file mode 100644 index 0000000000..003d44ef1a --- /dev/null +++ b/vlib/v/checker/tests/error_with_comment_with_lf_ending.vv @@ -0,0 +1,2 @@ +// Empty lines don't cause an issue but as soon as there's a comment with a CRLF ending, it fails +This should cause an error! \ No newline at end of file diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index 48e4066555..b14ce461ac 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -1092,10 +1092,14 @@ fn (mut s Scanner) text_scan() token.Token { if nextc == `/` { start := s.pos + 1 s.ignore_line() - comment_line_end := s.pos - s.pos-- - // fix line_nr, \n was read; the comment is marked on the next line - s.line_nr-- + mut comment_line_end := s.pos + if s.text[s.pos-1] == `\r` { + comment_line_end-- + } else { + // fix line_nr, \n was read; the comment is marked on the next line + s.pos-- + s.line_nr-- + } if s.should_parse_comment() { s.line_comment = s.text[start + 1..comment_line_end] mut comment := s.line_comment.trim_space()