cmd/compile: check and report imported package mismatch #71549
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
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
The text was updated successfully, but these errors were encountered: