dst icon indicating copy to clipboard operation
dst copied to clipboard

Fails to correctly handle multi-alias imports.

Open dave opened this issue 5 years ago • 2 comments

When dst automatically manages the imports block, the imports are internally keyed by path. This incorrectly assumes that only one import for each package path is possible. Although very rare, it is possible to add the same package multiple times with different aliases.

See: https://github.com/golang/go/commit/3409ce39bfd7584523b7a8c150a310cea92d879d

In TestLoadStdLibAll we test that the entire standard library is able to be parsed and rebuilt including management of the imports block. This test fails for the two files server.go and request.go in net/http because of this.

In order to handle this gracefully would involve a major rewrite of the import management code which is the most complex part of dst. For now I've skipped the TestLoadStdLibAll for these two files.

Re: @dmitshur

dave avatar May 12 '20 10:05 dave

This has come up again in the Go 1.15 standard library. I will exclude src/crypto/x509/x509.go from this test because it now has a duplicate import. This has come up twice now so I really should fix it.

p.s. I wonder if it was intentional to add a duplicate crypto/sha1 import in https://github.com/golang/go/commit/6f3a9515b6bb879472f3b3443a052b07ed11ee2f @katiehockman

dave avatar Aug 23 '20 08:08 dave

@dave Nope that wasn't intentional. I think it should keep the import that golang/go@6f3a951 added and remove the blank identifier import. Thanks for pointing that out.

katiehockman avatar Aug 25 '20 15:08 katiehockman