protoc-gen-go: predeclared identifiers in cleanPackageName#722
protoc-gen-go: predeclared identifiers in cleanPackageName#722neild merged 1 commit intogolang:masterfrom greenhouse-org:predeclared
Conversation
Don't generate identifiers that conflict with predeclared identifiers, prepend with "_" instead. Signed-off-by: Arjun Sreedharan <asreedharan@pivotal.io>
|
While naming a package name as a built-in identifier is not great, isn't this a breaking change? |
|
In the case of a package with a name that conflicts with a predefined identifier, that is imported without a local renaming, and that doesn't conflict with any identifier used in the places it is imported, this could be a breaking change. Testing the change inside Google's codebase isn't likely to turn up anything broken by this, because our local style is to always rename imported proto packages. I think generating a local rename that conflicts with a predefined identifier (e.g., |
SGTM.
I believe we should keep the existing logic for determining package names. In most cases, the user should specify the Also, I can understand hardcoding the keywords since they cannot be used as identifiers and it is very unlikely that we'll add new keywords even in Go2 (at least the generics proposal seems to make a conscious effort to avoid a new keyword). However, it seems more plausible that new built-in identifiers may be added to Go over time, which would presumably be added to the backlist. The idea that package names can can change over time is concerning. |
Don't generate identifiers that conflict with predeclared identifiers, prepend with "_" instead. Change-Id: I85e29d1861bc225df29949b26f4ae4a740bb4a66 Cherry-Pick: github.com/golang/protobuf@31e0d063dd98c052257e5b69eeb006818133f45c Original-Author: Sam Smith <sesmith177@gmail.com> Reviewed-on: https://go-review.googlesource.com/c/151423 Reviewed-by: Damien Neil <dneil@google.com>
Don't generate identifiers that conflict with predeclared identifiers, prepend with "_" instead. This matches the behavior for package names that are Go keywords.
We ran into this issue during envoyproxy/envoy#4556. Code with import statement:
was being generated and would not compile.
The list of predeclared indentifiers was taken from: https://golang.org/ref/spec#Predeclared_identifiers