Open quasilyte opened 6 years ago
The problem: astcopy functions do not copy ast.Object fields because some projects may not care about them at all (go/types.Object is better and deprecates ast.Object). But if for whatever reason user must copy objects, there will be troubles.
ast.Object
go/types.Object
I'm proposing this functions:
func IdentObjects(dst, src *ast.Ident) {/**/} func ScopeObjects(dst, src *ast.Scope) {/**/} func PackageObjects(dst, src *ast.Package) {/**/}
So, copy of *ast.Ident with objects may be done this way:
*ast.Ident
y := astcopy.Ident(x) astcopy.IdentObjects(y, x)
This can be wrapped by user into simple function:
func copyIdent(x) *ast.Ident { y := astcopy.Ident(x) astcopy.IdentObjects(y, x) return y }
This way, we avoid quite expensive copy that may be unnecessary in a first place and provide a way to copy objects if they are required.
Note that copying objects may be non-trivial. It needs some investigation and problem overview beforehand.
WDYT about astcopy.IdentDeep ?
astcopy.IdentDeep
@cristaloleg that could work too.
This is not high priority though. go-critic will never need that.
Although it's good that we have an idea how to add this feature if someone really needs it. We are prepared. :)
The problem: astcopy functions do not copy
ast.Object
fields because some projects may not care about them at all (go/types.Object
is better and deprecatesast.Object
). But if for whatever reason user must copy objects, there will be troubles.I'm proposing this functions:
So, copy of
*ast.Ident
with objects may be done this way:This can be wrapped by user into simple function:
This way, we avoid quite expensive copy that may be unnecessary in a first place and provide a way to copy objects if they are required.
Note that copying objects may be non-trivial. It needs some investigation and problem overview beforehand.