From 8adc8ed103d1eb88713d72e4a3330489155dca9c Mon Sep 17 00:00:00 2001 From: Lukas Neubert Date: Tue, 1 Dec 2020 21:32:34 +0100 Subject: [PATCH] parser: do not fail on comment direct after import (#7071) --- .../comparing_typesymbol_to_a_type_should_not_compile.out | 2 +- .../comparing_typesymbol_to_a_type_should_not_compile.vv | 0 vlib/v/fmt/tests/comment_after_import_expected.vv | 5 +++++ vlib/v/fmt/tests/comment_after_import_input.vv | 4 ++++ vlib/v/parser/parser.v | 2 +- 5 files changed, 11 insertions(+), 2 deletions(-) rename vlib/v/checker/{ => tests}/comparing_typesymbol_to_a_type_should_not_compile.out (66%) rename vlib/v/checker/{ => tests}/comparing_typesymbol_to_a_type_should_not_compile.vv (100%) create mode 100644 vlib/v/fmt/tests/comment_after_import_expected.vv create mode 100644 vlib/v/fmt/tests/comment_after_import_input.vv diff --git a/vlib/v/checker/comparing_typesymbol_to_a_type_should_not_compile.out b/vlib/v/checker/tests/comparing_typesymbol_to_a_type_should_not_compile.out similarity index 66% rename from vlib/v/checker/comparing_typesymbol_to_a_type_should_not_compile.out rename to vlib/v/checker/tests/comparing_typesymbol_to_a_type_should_not_compile.out index 5a40312727..6cd28016a7 100644 --- a/vlib/v/checker/comparing_typesymbol_to_a_type_should_not_compile.out +++ b/vlib/v/checker/tests/comparing_typesymbol_to_a_type_should_not_compile.out @@ -1,4 +1,4 @@ -vlib/v/checker/comparing_typesymbol_to_a_type_should_not_compile.vv:12:12: error: possible type mismatch of compared values of `==` operation +vlib/v/checker/tests/comparing_typesymbol_to_a_type_should_not_compile.vv:12:12: error: possible type mismatch of compared values of `==` operation 10 | x := ityp == table.string_type 11 | // the next line should produce at least a warning, or even an error, without an explicit cast: 12 | z := isym == table.string_type diff --git a/vlib/v/checker/comparing_typesymbol_to_a_type_should_not_compile.vv b/vlib/v/checker/tests/comparing_typesymbol_to_a_type_should_not_compile.vv similarity index 100% rename from vlib/v/checker/comparing_typesymbol_to_a_type_should_not_compile.vv rename to vlib/v/checker/tests/comparing_typesymbol_to_a_type_should_not_compile.vv diff --git a/vlib/v/fmt/tests/comment_after_import_expected.vv b/vlib/v/fmt/tests/comment_after_import_expected.vv new file mode 100644 index 0000000000..722b07b144 --- /dev/null +++ b/vlib/v/fmt/tests/comment_after_import_expected.vv @@ -0,0 +1,5 @@ +import semver + +// as semver +fn main() { +} diff --git a/vlib/v/fmt/tests/comment_after_import_input.vv b/vlib/v/fmt/tests/comment_after_import_input.vv new file mode 100644 index 0000000000..fbb98871ba --- /dev/null +++ b/vlib/v/fmt/tests/comment_after_import_input.vv @@ -0,0 +1,4 @@ +import semver// as semver + +fn main() { +} diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index d24903c0c2..7d0d38584a 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -1624,7 +1624,7 @@ fn (mut p Parser) import_stmt() ast.Import { } pos_t := p.tok.position() if import_pos.line_nr == pos_t.line_nr { - if p.tok.kind !in [.lcbr, .eof] { + if p.tok.kind !in [.lcbr, .eof, .comment] { p.error_with_pos('cannot import multiple modules at a time', pos_t) } }