Skip to content

astcopy: make it possible to copy ast.Object #1

@quasilyte

Description

@quasilyte

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.

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions