From 7c0a298701d5f63993b08abdca85a374b5344cdc Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 11 Jul 2020 14:53:21 +0300 Subject: [PATCH] vfmt: fix crash when a .v file contains only imports --- vlib/v/fmt/fmt.v | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index b585802fc1..b3f39d8b25 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -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) {