1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vfmt: fix crash when a .v file contains only imports

This commit is contained in:
Delyan Angelov 2020-07-11 14:53:21 +03:00
parent 3aeca70970
commit 7c0a298701

View File

@ -76,7 +76,8 @@ pub fn fmt(file ast.File, table &table.Table, is_debug bool) string {
// for comment in file.comments { println('$comment.line_nr $comment.text') } // for comment in file.comments { println('$comment.line_nr $comment.text') }
f.imports(f.file.imports) // now that we have all autoimports, handle them f.imports(f.file.imports) // now that we have all autoimports, handle them
res := f.out.str().trim_space() + '\n' res := f.out.str().trim_space() + '\n'
return res[..f.import_pos] + f.out_imports.str() + res[f.import_pos..] // + '\n' bounded_import_pos := util.imin(res.len,f.import_pos)
return res[..bounded_import_pos] + f.out_imports.str() + res[bounded_import_pos..] // + '\n'
} }
pub fn (mut f Fmt) process_file_imports(file &ast.File) { pub fn (mut f Fmt) process_file_imports(file &ast.File) {