golang / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
9.29k stars 610 forks source link

AST duplication compare only by paths, not by alias. Fix it #586

Closed TheZeroSlave closed 2 years ago

TheZeroSlave commented 2 years ago

HI. AST removing duplicates works not correct for local aliasing. If you have several imports ta package with different local names - it will bring some pain like "unknown package" because ast remove all packages with another local naming. From the library source: go/ast/filter.go:458

        seen := make(map[string]bool)
        for _, filename := range filenames {
            f := pkg.Files[filename]
            for _, imp := range f.Imports {
                if path := imp.Path.Value; !seen[path] {
                    // TODO: consider handling cases where:
                    // - 2 imports exist with the same import path but
                    //   have different local names (one should probably
                    //   keep both of them)
                    // - 2 imports exist but only one has a comment
                    // - 2 imports exist and they both have (possibly
                    //   different) comments
                    imports = append(imports, imp)
                    seen[path] = true
                }
            }
        }

So this PR tries to fix this by handling duplicates by skipping them.

googlebot commented 2 years ago

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

google-cla[bot] commented 2 years ago

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

TheZeroSlave commented 2 years ago

@googlebot I signed it!

googlebot commented 2 years ago

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

google-cla[bot] commented 2 years ago

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

codyoss commented 2 years ago

Closing due to lack of response.