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

pull/5801/head
Delyan Angelov 2020-07-11 14:53:21 +03:00
parent 3aeca70970
commit 7c0a298701
1 changed files with 2 additions and 1 deletions

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') }
f.imports(f.file.imports) // now that we have all autoimports, handle them
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) {