1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fmt: fix removal of selective imported types, used as array elements (#16963)

This commit is contained in:
zakuro
2023-01-13 16:30:28 +09:00
committed by GitHub
parent ba091a36dd
commit c766ce4fe5
3 changed files with 30 additions and 14 deletions

View File

@ -285,16 +285,23 @@ pub fn (mut f Fmt) short_module(name string) string {
pub fn (mut f Fmt) mark_types_import_as_used(typ ast.Type) { pub fn (mut f Fmt) mark_types_import_as_used(typ ast.Type) {
sym := f.table.sym(typ) sym := f.table.sym(typ)
if sym.info is ast.Map { match sym.info {
map_info := sym.map_info() ast.Map {
f.mark_types_import_as_used(map_info.key_type) map_info := sym.map_info()
f.mark_types_import_as_used(map_info.value_type) f.mark_types_import_as_used(map_info.key_type)
return f.mark_types_import_as_used(map_info.value_type)
} return
if sym.info is ast.GenericInst {
for concrete_typ in sym.info.concrete_types {
f.mark_types_import_as_used(concrete_typ)
} }
ast.Array, ast.ArrayFixed {
f.mark_types_import_as_used(sym.info.elem_type)
return
}
ast.GenericInst {
for concrete_typ in sym.info.concrete_types {
f.mark_types_import_as_used(concrete_typ)
}
}
else {}
} }
name := sym.name.split('[')[0] // take `Type` from `Type[T]` name := sym.name.split('[')[0] // take `Type` from `Type[T]`
f.mark_import_as_used(name) f.mark_import_as_used(name)

View File

@ -14,6 +14,7 @@ import mod {
FnArgGeneric, FnArgGeneric,
FnArgTypeParam1, FnArgTypeParam1,
FnArgTypeParam2, FnArgTypeParam2,
FnArgVariadic,
FnRet, FnRet,
FnRetGeneric, FnRetGeneric,
FnRetTypeParam1, FnRetTypeParam1,
@ -23,8 +24,10 @@ import mod {
InterfaceMethodRet, InterfaceMethodRet,
RightOfAs, RightOfAs,
RightOfIs, RightOfIs,
StructArrayFieldElem,
StructEmbed, StructEmbed,
StructField, StructField,
StructFixedArrayFieldElem,
StructMapFieldKey, StructMapFieldKey,
StructMapFieldValue, StructMapFieldValue,
StructMethodArg, StructMethodArg,
@ -42,9 +45,11 @@ type Fn = fn (FnAliasParam) FnAliasRet
struct Struct { struct Struct {
StructEmbed StructEmbed
v StructField v StructField
ref &StructRefField ref &StructRefField
map map[StructMapFieldKey]StructMapFieldValue map map[StructMapFieldKey]StructMapFieldValue
arr []StructArrayFieldElem
arr_fixed [2]StructFixedArrayFieldElem
} }
fn (s Struct) method(v StructMethodArg) StructMethodRet { fn (s Struct) method(v StructMethodArg) StructMethodRet {
@ -60,7 +65,7 @@ interface Interface {
f(InterfaceMethodArg) InterfaceMethodRet f(InterfaceMethodArg) InterfaceMethodRet
} }
fn f(v FnArg) FnRet { fn f(v FnArg, vv ...FnArgVariadic) FnRet {
if v is RightOfIs { if v is RightOfIs {
} }
_ = v as RightOfAs _ = v as RightOfAs

View File

@ -11,6 +11,7 @@ import mod {
Unused, Unused,
StructEmbed, StructField, StructRefField StructEmbed, StructField, StructRefField
StructMapFieldKey, StructMapFieldValue, StructMapFieldKey, StructMapFieldValue,
StructArrayFieldElem, StructFixedArrayFieldElem
StructMethodArg, StructMethodArg,
StructMethodArgGeneric, StructMethodArgGeneric,
StructMethodRet, StructMethodRet,
@ -21,6 +22,7 @@ import mod {
InterfaceMethodRet, InterfaceMethodRet,
FnArg, FnArg,
FnArgVariadic
FnArgGeneric FnArgGeneric
FnArgTypeParam1 FnArgTypeParam1
FnArgTypeParam2 FnArgTypeParam2
@ -48,6 +50,8 @@ struct Struct {
v StructField v StructField
ref &StructRefField ref &StructRefField
map map[StructMapFieldKey]StructMapFieldValue map map[StructMapFieldKey]StructMapFieldValue
arr []StructArrayFieldElem
arr_fixed [2]StructFixedArrayFieldElem
} }
fn (s Struct) method(v StructMethodArg) StructMethodRet { fn (s Struct) method(v StructMethodArg) StructMethodRet {
@ -63,7 +67,7 @@ interface Interface {
f(InterfaceMethodArg) InterfaceMethodRet f(InterfaceMethodArg) InterfaceMethodRet
} }
fn f(v FnArg) FnRet { fn f(v FnArg, vv ...FnArgVariadic) FnRet {
if v is RightOfIs {} if v is RightOfIs {}
_ = v as RightOfAs _ = v as RightOfAs