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

cmd/compile: check and report imported package mismatch #71549

Open
cherrymui opened this issue Feb 3, 2025 · 0 comments
Open

cmd/compile: check and report imported package mismatch #71549

cherrymui opened this issue Feb 3, 2025 · 0 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@cherrymui
Copy link
Member

googleapis/gapic-generator-go#1608 boils down to a mismatch of imported package objects. Specifically, a package A imports B and C, and B also imports C. Probably due to a bug in the build system, it created multiple versions of C, C1 and C2, with slightly different source code. When building A, C1.a (or C1.x) is used for package C, whereas when building B, C2.a is used. This confuses the compiler, which emits some type mismatch error (like cannot use name (type string) as type int32 in field value).

Inconsistent imports shouldn't happen with go build. But it might happen with other build system. For the case above, it builds with Bazel, and C is proto library. Somehow it has two different proto code generators, which generate slightly different Go code C1 and C2, which get pulled into the same build.

This clearly would not work. But the compiler error is hard to understand and hard to debug. It is better to detect the error upfront and emit a clear error message. Go objects carries fingerprints, which the linker uses to detect similar mismatches. The compiler should be able to use that and detect mismatch as well. Then in the situation above, when compiling A, it would see that B is expecting fingerprint(C1) but C has fingerprint(C2), and error out.

cc @znkr @codyoss @stapelberg

@cherrymui cherrymui added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 3, 2025
@cherrymui cherrymui added this to the Backlog milestone Feb 3, 2025
@cherrymui cherrymui added the compiler/runtime Issues related to the Go compiler and/or runtime. label Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Development

No branches or pull requests

2 participants