From 968cb13a36cd7dd8100c2b5b66a7be364555b3ca Mon Sep 17 00:00:00 2001 From: zakuro Date: Thu, 15 Apr 2021 08:29:17 +0900 Subject: [PATCH] fmt: mark types import as used in interface (#9718) --- vlib/v/fmt/fmt.v | 5 +++ vlib/v/fmt/tests/import_selective_expected.vv | 31 +++++++++++++++++ vlib/v/fmt/tests/import_selective_input.vv | 34 +++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index aa9f4c7417..ea464605e4 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -1164,6 +1164,7 @@ pub fn (mut f Fmt) interface_decl(node ast.InterfaceDecl) { ft = f.short_module(ft) } f.writeln('\t$field.name $ft') + f.mark_types_import_as_used(field.typ) } for method in node.methods { f.write('\t') @@ -1171,6 +1172,10 @@ pub fn (mut f Fmt) interface_decl(node ast.InterfaceDecl) { f.comments(method.comments, inline: true, has_nl: false, level: .indent) f.writeln('') f.comments(method.next_comments, inline: false, has_nl: true, level: .indent) + for param in method.params { + f.mark_types_import_as_used(param.typ) + } + f.mark_types_import_as_used(method.return_type) } f.writeln('}\n') } diff --git a/vlib/v/fmt/tests/import_selective_expected.vv b/vlib/v/fmt/tests/import_selective_expected.vv index 03e503a4a7..4d3f9517a9 100644 --- a/vlib/v/fmt/tests/import_selective_expected.vv +++ b/vlib/v/fmt/tests/import_selective_expected.vv @@ -5,6 +5,37 @@ import os { file_ext, user_os, } +import mod { + FnArg, + FnRet, + InterfaceField, + InterfaceMethodArg, + InterfaceMethodRet, + StructEmbed, + StructField, + StructMethodArg, + StructMethodRet, + StructRefField, +} + +struct Struct { + StructEmbed + v StructField + ref &StructRefField +} + +fn (s Struct) method(v StructMethodArg) StructMethodRet { + return {} +} + +interface Interface { + v InterfaceField + f(InterfaceMethodArg) InterfaceMethodRet +} + +fn f(v FnArg) FnRet { + return {} +} struct App { command &Command diff --git a/vlib/v/fmt/tests/import_selective_input.vv b/vlib/v/fmt/tests/import_selective_input.vv index bd7348db6f..5af68c42ca 100644 --- a/vlib/v/fmt/tests/import_selective_input.vv +++ b/vlib/v/fmt/tests/import_selective_input.vv @@ -7,6 +7,39 @@ import math.complex { complex, Complex } import os { input, user_os, file_ext } +import mod { + Unused, + StructEmbed, StructField, StructRefField + StructMethodArg, + StructMethodRet + + InterfaceField, + InterfaceMethodArg, + InterfaceMethodRet, + + FnArg, + FnRet, +} + +struct Struct { + StructEmbed + v StructField + ref &StructRefField +} + +fn (s Struct) method(v StructMethodArg) StructMethodRet { + return {} +} + +interface Interface { + v InterfaceField + f(InterfaceMethodArg) InterfaceMethodRet +} + +fn f(v FnArg) FnRet { + return {} +} + struct App { command &Command } @@ -26,3 +59,4 @@ fn main() { println(file_ext('main.v')) println(imaginary(1)) } +