fmt: fix 'strings' name variable call generate auto import (fix #9713) (#14485)

yuyi 2022-05-21 20:01:58 +08:00 committed by Jef Roosens
parent 39c1ae3a43
commit 0227573ea9
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 7 additions and 1 deletions

View File

@ -1651,7 +1651,8 @@ pub fn (mut f Fmt) call_expr(node ast.CallExpr) {
// `time.now()` without `time imported` is processed as a method call with `time` being // `time.now()` without `time imported` is processed as a method call with `time` being
// a `node.left` expression. Import `time` automatically. // a `node.left` expression. Import `time` automatically.
// TODO fetch all available modules // TODO fetch all available modules
if node.left.name in ['time', 'os', 'strings', 'math', 'json', 'base64'] { if node.left.name in ['time', 'os', 'strings', 'math', 'json', 'base64']
&& !node.left.scope.known_var(node.left.name) {
f.file.imports << ast.Import{ f.file.imports << ast.Import{
mod: node.left.name mod: node.left.name
alias: node.left.name alias: node.left.name

View File

@ -0,0 +1,5 @@
fn main() {
strings := 'hello'
a := strings.repeat(2)
println(a)
}