From b18d091e186bc4e32eb8b266623485b919f4aefd Mon Sep 17 00:00:00 2001 From: Lukas Neubert Date: Wed, 24 Feb 2021 19:33:17 +0100 Subject: [PATCH] fmt: fix pos of added imports (#8931) --- vlib/v/fmt/fmt.v | 3 +++ vlib/v/fmt/tests/import_auto_added_expected.vv | 7 +++++++ vlib/v/fmt/tests/import_auto_added_input.vv | 5 +++++ 3 files changed, 15 insertions(+) create mode 100644 vlib/v/fmt/tests/import_auto_added_expected.vv create mode 100644 vlib/v/fmt/tests/import_auto_added_input.vv 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() +}