vfmt: fix removal of selective imported type used in map (#12030)

pull/12037/head
zakuro 2021-10-01 21:14:21 +09:00 committed by GitHub
parent 41de0c3c6a
commit ce0867f40c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 0 deletions

View File

@ -245,6 +245,12 @@ pub fn (mut f Fmt) short_module(name string) string {
pub fn (mut f Fmt) mark_types_import_as_used(typ ast.Type) {
sym := f.table.get_type_symbol(typ)
if sym.info is ast.Map {
map_info := sym.map_info()
f.mark_types_import_as_used(map_info.key_type)
f.mark_types_import_as_used(map_info.value_type)
return
}
name := sym.name.split('<')[0] // take `Type` from `Type<T>`
f.mark_import_as_used(name)
}

View File

@ -18,6 +18,8 @@ import mod {
RightOfIs,
StructEmbed,
StructField,
StructMapFieldKey,
StructMapFieldValue,
StructMethodArg,
StructMethodArgGeneric,
StructMethodRet,
@ -29,6 +31,7 @@ struct Struct {
StructEmbed
v StructField
ref &StructRefField
map map[StructMapFieldKey]StructMapFieldValue
}
fn (s Struct) method(v StructMethodArg) StructMethodRet {

View File

@ -10,6 +10,7 @@ import os {
import mod {
Unused,
StructEmbed, StructField, StructRefField
StructMapFieldKey, StructMapFieldValue,
StructMethodArg,
StructMethodArgGeneric,
StructMethodRet,
@ -34,6 +35,7 @@ struct Struct {
StructEmbed
v StructField
ref &StructRefField
map map[StructMapFieldKey]StructMapFieldValue
}
fn (s Struct) method(v StructMethodArg) StructMethodRet {