From 600f6ad2a063dfba9dffb259ed02390c859987e3 Mon Sep 17 00:00:00 2001 From: zakuro Date: Thu, 18 Feb 2021 04:42:26 +0900 Subject: [PATCH] fmt: do not prepend mod to selectively imported types from nested module (#8805) --- vlib/v/fmt/fmt.v | 4 +++- vlib/v/fmt/tests/import_selective_expected.vv | 6 ++++++ vlib/v/fmt/tests/import_selective_input.vv | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 0e899a10d1..874f3238e6 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -80,9 +80,11 @@ pub fn fmt(file ast.File, table &table.Table, pref &pref.Preferences, is_debug b pub fn (mut f Fmt) process_file_imports(file &ast.File) { for imp in file.imports { - f.mod2alias[imp.mod.all_after_last('.')] = imp.alias + mod := imp.mod.all_after_last('.') + f.mod2alias[mod] = imp.alias for sym in imp.syms { f.mod2alias['${imp.mod}.$sym.name'] = sym.name + f.mod2alias['${mod}.$sym.name'] = sym.name f.mod2alias[sym.name] = sym.name f.import_syms_used[sym.name] = false } diff --git a/vlib/v/fmt/tests/import_selective_expected.vv b/vlib/v/fmt/tests/import_selective_expected.vv index 388aed55e3..c111d49c1b 100644 --- a/vlib/v/fmt/tests/import_selective_expected.vv +++ b/vlib/v/fmt/tests/import_selective_expected.vv @@ -1,12 +1,18 @@ import math { max, min } +import math.complex { complex, Complex } import os { user_os, file_ext, } +fn imaginary(im f64) Complex { + return complex(0, im) +} + fn main() { println(max(0.1, 0.2)) println(min(0.1, 0.2)) println(user_os()) println(file_ext('main.v')) + println(imaginary(1)) } diff --git a/vlib/v/fmt/tests/import_selective_input.vv b/vlib/v/fmt/tests/import_selective_input.vv index 7ce3f5f755..fa78d57367 100644 --- a/vlib/v/fmt/tests/import_selective_input.vv +++ b/vlib/v/fmt/tests/import_selective_input.vv @@ -1,12 +1,18 @@ import math { max, min, } +import math.complex { complex, Complex } import os { input, user_os, file_ext } +fn imaginary(im f64) Complex { + return complex(0, im) +} + fn main() { println(max(0.1, 0.2)) println(min(0.1, 0.2)) println(user_os()) println(file_ext('main.v')) + println(imaginary(1)) }