Skip to content

x/tools/go/ast/astutil: AddNamedImport isn't symmetrical to DeleteNamedImport #28605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dmitshur opened this issue Nov 5, 2018 · 1 comment
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dmitshur
Copy link
Contributor

dmitshur commented Nov 5, 2018

astutil.DeleteNamedImport is documented as:

// DeleteNamedImport deletes the import with the given name and path from the file f, if present.

And it works as expected. It's a low-level AST manipulation primitive that allows one to delete the exact import statement with the provided name and import path.

astutil.AddNamedImport has a symmetrical signature, and its documentation suggests it would do the symmetrical operation of adding an optionally renamed import.

However, it has a bug where once the AST has an import with the specified import path, it's not possible to add other imports with the same import path but different names.

I have a fix with test cases, will send a CL soon. /cc @heschik @alandonovan

This bug is causing #16411.

@dmitshur dmitshur self-assigned this Nov 5, 2018
@gopherbot gopherbot added this to the Unreleased milestone Nov 5, 2018
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/147448 mentions this issue: go/ast/astutil: allow AddNamedImport to add imports with different names

@dmitshur dmitshur added the NeedsFix The path to resolution is known, but the work has not been done. label Nov 7, 2018
@golang golang locked and limited conversation to collaborators Nov 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

2 participants