diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 70396184e7..0a5a27f42a 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -257,6 +257,7 @@ pub fn (mut f Fmt) imports(imports []ast.Import) { f.out_imports.writeln('import ${imp_stmt_str}\n') } else if imports.len > 1 { */ + mut already_imported := map[string]bool{} for imp in imports { if imp.mod !in f.used_imports { // TODO bring back once only unused imports are removed @@ -265,8 +266,12 @@ pub fn (mut f Fmt) imports(imports []ast.Import) { if imp.mod in f.auto_imports && imp.mod !in f.used_imports { continue } - f.out_imports.write('import ') - f.out_imports.writeln(f.imp_stmt_str(imp)) + import_text := 'import ${f.imp_stmt_str(imp)}' + if already_imported[import_text] { + continue + } + already_imported[import_text] = true + f.out_imports.writeln(import_text) num_imports++ } if num_imports > 0 { diff --git a/vlib/v/fmt/tests/import_multiple_input.vv b/vlib/v/fmt/tests/import_multiple_input.vv index 5769710c0f..0c11afe4a2 100644 --- a/vlib/v/fmt/tests/import_multiple_input.vv +++ b/vlib/v/fmt/tests/import_multiple_input.vv @@ -1,5 +1,6 @@ import math import os +import math const ( mypi = math.pi