mirror of
https://github.com/golang/go
synced 2024-11-18 08:14:41 -07:00
internal/analysisinternal: add anonymous structs & interfaces to
Fillstruct wasn't able to fill structs with fileds that held anonymous structs or maps with anonymous structs/interfaces. By adding *types.Struct and *types.Interface support in TypeExpr(), fillstruct is now works for those as well. Fixes golang/go#40980 Change-Id: I2a1d6d4db237800197cf14e3ad5067a0e7ab701a Reviewed-on: https://go-review.googlesource.com/c/tools/+/249999 Reviewed-by: Rebecca Stambler <rstambler@golang.org> Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
c024452afb
commit
b303f430e3
@ -198,8 +198,12 @@ func TypeExpr(fset *token.FileSet, f *ast.File, pkg *types.Package, typ types.Ty
|
|||||||
X: ast.NewIdent(pkgName),
|
X: ast.NewIdent(pkgName),
|
||||||
Sel: ast.NewIdent(t.Obj().Name()),
|
Sel: ast.NewIdent(t.Obj().Name()),
|
||||||
}
|
}
|
||||||
|
case *types.Struct:
|
||||||
|
return ast.NewIdent(t.String())
|
||||||
|
case *types.Interface:
|
||||||
|
return ast.NewIdent(t.String())
|
||||||
default:
|
default:
|
||||||
return nil // TODO: anonymous structs, but who does that
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
internal/lsp/testdata/lsp/primarymod/fillstruct/fill_struct_anon.go
vendored
Normal file
14
internal/lsp/testdata/lsp/primarymod/fillstruct/fill_struct_anon.go
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package fillstruct
|
||||||
|
|
||||||
|
type StructAnon struct {
|
||||||
|
a struct{}
|
||||||
|
b map[string]interface{}
|
||||||
|
c map[string]struct {
|
||||||
|
d int
|
||||||
|
e bool
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fill() {
|
||||||
|
_ := StructAnon{} //@suggestedfix("}", "refactor.rewrite")
|
||||||
|
}
|
20
internal/lsp/testdata/lsp/primarymod/fillstruct/fill_struct_anon.go.golden
vendored
Normal file
20
internal/lsp/testdata/lsp/primarymod/fillstruct/fill_struct_anon.go.golden
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
-- suggestedfix_fill_struct_anon_13_18 --
|
||||||
|
package fillstruct
|
||||||
|
|
||||||
|
type StructAnon struct {
|
||||||
|
a struct{}
|
||||||
|
b map[string]interface{}
|
||||||
|
c map[string]struct {
|
||||||
|
d int
|
||||||
|
e bool
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fill() {
|
||||||
|
_ := StructAnon{
|
||||||
|
a: struct{}{},
|
||||||
|
b: map[string]interface{}{},
|
||||||
|
c: map[string]struct{d int; e bool}{},
|
||||||
|
} //@suggestedfix("}", "refactor.rewrite")
|
||||||
|
}
|
||||||
|
|
2
internal/lsp/testdata/lsp/summary.txt.golden
vendored
2
internal/lsp/testdata/lsp/summary.txt.golden
vendored
@ -12,7 +12,7 @@ DiagnosticsCount = 44
|
|||||||
FoldingRangesCount = 2
|
FoldingRangesCount = 2
|
||||||
FormatCount = 6
|
FormatCount = 6
|
||||||
ImportCount = 8
|
ImportCount = 8
|
||||||
SuggestedFixCount = 37
|
SuggestedFixCount = 38
|
||||||
FunctionExtractionCount = 11
|
FunctionExtractionCount = 11
|
||||||
DefinitionsCount = 63
|
DefinitionsCount = 63
|
||||||
TypeDefinitionsCount = 2
|
TypeDefinitionsCount = 2
|
||||||
|
Loading…
Reference in New Issue
Block a user