go
build_error
ai_generated
true
protoc-gen-go:错误:在文件 "user.proto" 和 "user_v2.proto" 中重复的符号 "pb.User"
protoc-gen-go: error: duplicate symbol "pb.User" in file "user.proto" and "user_v2.proto"
ID: go/proto-duplicate-symbol
80%修复率
87%置信度
0证据数
2024-08-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| protoc-gen-go 1.31+ | active | — | — | — |
根因分析
两个 .proto 文件声明了相同的完全限定消息名(相同 package + message)并被一起编译,导致生成的 Go 代码中符号冲突。
English
Two .proto files declare the same fully-qualified message name (same package + message) and are compiled together, causing a symbol collision in generated Go code.
解决方案
-
95% 成功率
Give each file a distinct proto package: // user.proto package pb.v1; // user_v2.proto package pb.v2;
-
85% 成功率
Use buf to detect and lint duplicate symbols across the workspace: buf lint buf breaking --against '.git#branch=main'
无效尝试
常见但无效的做法:
-
90% 失败
The collision is on the protobuf fully-qualified name, not the Go package; protoc still errors.
-
85% 失败
At link time the generated Go files still declare identical Go types and the Go build fails.