Skip to content

Commit 968cb13

Browse files
authored
fmt: mark types import as used in interface (#9718)
1 parent 56e1574 commit 968cb13

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

vlib/v/fmt/fmt.v

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,13 +1164,18 @@ pub fn (mut f Fmt) interface_decl(node ast.InterfaceDecl) {
11641164
ft = f.short_module(ft)
11651165
}
11661166
f.writeln('\t$field.name $ft')
1167+
f.mark_types_import_as_used(field.typ)
11671168
}
11681169
for method in node.methods {
11691170
f.write('\t')
11701171
f.write(method.stringify(f.table, f.cur_mod, f.mod2alias).after('fn '))
11711172
f.comments(method.comments, inline: true, has_nl: false, level: .indent)
11721173
f.writeln('')
11731174
f.comments(method.next_comments, inline: false, has_nl: true, level: .indent)
1175+
for param in method.params {
1176+
f.mark_types_import_as_used(param.typ)
1177+
}
1178+
f.mark_types_import_as_used(method.return_type)
11741179
}
11751180
f.writeln('}\n')
11761181
}

vlib/v/fmt/tests/import_selective_expected.vv

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,37 @@ import os {
55
file_ext,
66
user_os,
77
}
8+
import mod {
9+
FnArg,
10+
FnRet,
11+
InterfaceField,
12+
InterfaceMethodArg,
13+
InterfaceMethodRet,
14+
StructEmbed,
15+
StructField,
16+
StructMethodArg,
17+
StructMethodRet,
18+
StructRefField,
19+
}
20+
21+
struct Struct {
22+
StructEmbed
23+
v StructField
24+
ref &StructRefField
25+
}
26+
27+
fn (s Struct) method(v StructMethodArg) StructMethodRet {
28+
return {}
29+
}
30+
31+
interface Interface {
32+
v InterfaceField
33+
f(InterfaceMethodArg) InterfaceMethodRet
34+
}
35+
36+
fn f(v FnArg) FnRet {
37+
return {}
38+
}
839

940
struct App {
1041
command &Command

vlib/v/fmt/tests/import_selective_input.vv

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,39 @@ import math.complex { complex, Complex }
77
import os {
88
input, user_os, file_ext }
99

10+
import mod {
11+
Unused,
12+
StructEmbed, StructField, StructRefField
13+
StructMethodArg,
14+
StructMethodRet
15+
16+
InterfaceField,
17+
InterfaceMethodArg,
18+
InterfaceMethodRet,
19+
20+
FnArg,
21+
FnRet,
22+
}
23+
24+
struct Struct {
25+
StructEmbed
26+
v StructField
27+
ref &StructRefField
28+
}
29+
30+
fn (s Struct) method(v StructMethodArg) StructMethodRet {
31+
return {}
32+
}
33+
34+
interface Interface {
35+
v InterfaceField
36+
f(InterfaceMethodArg) InterfaceMethodRet
37+
}
38+
39+
fn f(v FnArg) FnRet {
40+
return {}
41+
}
42+
1043
struct App {
1144
command &Command
1245
}
@@ -26,3 +59,4 @@ fn main() {
2659
println(file_ext('main.v'))
2760
println(imaginary(1))
2861
}
62+

0 commit comments

Comments
 (0)