Skip to content
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

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

dmitshur opened this issue Nov 5, 2018 · 1 comment


Copy link

@dmitshur 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
Copy link

@gopherbot gopherbot commented Nov 5, 2018

Change mentions this issue: go/ast/astutil: allow AddNamedImport to add imports with different names

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.