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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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) {
sym := f.table.sym(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
}
if sym.info is ast.GenericInst {
for concrete_typ in sym.info.concrete_types {
f.mark_types_import_as_used(concrete_typ)
match sym.info {
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
}
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]`
f.mark_import_as_used(name)

View File

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

View File

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