bugfix: v should not panic when encountering a file that consists only of comments

pull/3800/head
Delyan Angelov 2020-02-20 23:59:47 +02:00 committed by GitHub
parent e56bf42270
commit 88b402fcf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 1 deletions

View File

@ -828,7 +828,7 @@ pub fn (v mut V) parse_lib_imports() {
pidx := v.parse(file, .imports)
p_mod := v.parsers[pidx].mod
if p_mod != mod {
v.parsers[pidx].error_with_token_index('bad module definition: ${v.parsers[pidx].file_path} imports module "$mod" but $file is defined as module `$p_mod`', 1)
v.parsers[pidx].error_with_token_index('bad module definition: ${v.parsers[pidx].file_path} imports module "$mod" but $file is defined as module `$p_mod`', 0)
}
}
done_imports << mod

View File

@ -0,0 +1,5 @@
/*
module acommentedmodule
*/

View File

@ -0,0 +1,3 @@
import compiler.tests.modules.acommentedmodule
===output===
vlib/compiler/tests/modules/acommentedmodule/commentedfile.v:7:1: bad module definition: vlib/compiler/tests/modules/acommentedmodule/commentedfile.v imports module "compiler.tests.modules.acommentedmodule" but vlib/compiler/tests/modules/acommentedmodule/commentedfile.v is defined as module `main`

View File

@ -51,6 +51,7 @@ fn diff_files( file_result, file_expected string ) string {
}
pub fn run_repl_file(wd string, vexec string, file string) ?string {
vexec_folder := filepath.dir(vexec) + filepath.separator
fcontent := os.read_file(file) or { return error('Could not read file ${file}') }
content := fcontent.replace('\r', '')
input := content.all_before('===output===\n')
@ -74,6 +75,8 @@ pub fn run_repl_file(wd string, vexec string, file string) ?string {
.replace('... ', '')
.all_after('Use Ctrl-C or `exit` to exit\n')
.replace(wd + filepath.separator, '' )
.replace(vexec_folder, '')
.replace('\\', '/')
if result != output {
file_result := '${file}.result.txt'