diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 3cb1759454..b3cf37a8cc 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -236,6 +236,9 @@ pub fn (mut f Fmt) mod(mod ast.Module) { } f.attrs(mod.attrs) f.writeln('module $mod.short_name\n') + if f.import_pos == 0 { + f.import_pos = f.out.len + } } pub fn (mut f Fmt) mark_types_import_as_used(typ table.Type) { diff --git a/vlib/v/fmt/tests/import_auto_added_expected.vv b/vlib/v/fmt/tests/import_auto_added_expected.vv new file mode 100644 index 0000000000..2b9dc52a37 --- /dev/null +++ b/vlib/v/fmt/tests/import_auto_added_expected.vv @@ -0,0 +1,7 @@ +module main + +import time + +fn main() { + curr_time := time.now() +} diff --git a/vlib/v/fmt/tests/import_auto_added_input.vv b/vlib/v/fmt/tests/import_auto_added_input.vv new file mode 100644 index 0000000000..4c6a55919a --- /dev/null +++ b/vlib/v/fmt/tests/import_auto_added_input.vv @@ -0,0 +1,5 @@ +module main + +fn main() { + curr_time := time.now() +}