From cb14e42af8e49ec1dee212c19ad89770ab9901c3 Mon Sep 17 00:00:00 2001 From: zakuro Date: Sat, 10 Jul 2021 17:06:01 +0900 Subject: [PATCH] fmt: fix removal of selective imported Enum (#10729) --- vlib/v/fmt/fmt.v | 1 + vlib/v/fmt/tests/import_selective_expected.vv | 3 +++ vlib/v/fmt/tests/import_selective_input.vv | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index b21b6947b1..cdfefc5961 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1804,6 +1804,7 @@ pub fn (mut f Fmt) dump_expr(node ast.DumpExpr) { pub fn (mut f Fmt) enum_val(node ast.EnumVal) { name := f.short_module(node.enum_name) f.write(name + '.' + node.val) + f.mark_import_as_used(name) } pub fn (mut f Fmt) ident(node ast.Ident) { diff --git a/vlib/v/fmt/tests/import_selective_expected.vv b/vlib/v/fmt/tests/import_selective_expected.vv index a4bb43f935..8cdb26a964 100644 --- a/vlib/v/fmt/tests/import_selective_expected.vv +++ b/vlib/v/fmt/tests/import_selective_expected.vv @@ -6,6 +6,7 @@ import os { user_os, } import mod { + Enum, FnArg, FnRet, InterfaceField, @@ -40,6 +41,8 @@ fn f(v FnArg) FnRet { } _ = v as RightOfAs + println(Enum.val) + return {} } diff --git a/vlib/v/fmt/tests/import_selective_input.vv b/vlib/v/fmt/tests/import_selective_input.vv index 8a542fe0ea..12a08125ea 100644 --- a/vlib/v/fmt/tests/import_selective_input.vv +++ b/vlib/v/fmt/tests/import_selective_input.vv @@ -22,6 +22,8 @@ import mod { RightOfIs, RightOfAs, + + Enum } struct Struct { @@ -43,6 +45,8 @@ fn f(v FnArg) FnRet { if v is RightOfIs {} _ = v as RightOfAs + println(Enum.val) + return {} }