Copilot commented on code in PR #3971:
URL: https://github.com/apache/thrift/pull/3971#discussion_r4212141109
##########
compiler/cpp/src/thrift/generate/t_go_generator.cc:
##########
@@ -457,6 +457,19 @@ void t_go_generator::init_generator() {
package_dir_ = get_out_dir();
last_const_block_ = 0;
+ // The -remote stub's main() declares these local variables. An imported
package with one of
+ // these names would be shadowed by them, so reserve them before any import
is rendered; such a
+ // package is then imported under an alias in every file of this program.
+ if (!skip_remote_) {
+ for (const char* local :
+ {"cfg", "client", "cmd", "err", "framed",
"headers",
+ "host", "httptrans", "iprot", "m", "oprot",
"parsedUrl",
+ "parts", "port", "portStr", "protocol", "protocolFactory",
"trans",
+ "urlString", "useHttp"}) {
+ package_identifiers_set_.insert(local);
Review Comment:
These reservations can produce a duplicate Go import identifier because
`render_program_import()` accepts `tmp(value)` without checking that the
generated candidate is free. For example, if sorted includes first allocate
package `a.client0` as `client0` and later allocate `z.client`, the new
`client` reservation also aliases the latter to `client0`, so the generated
files fail to compile. Please make alias generation retry until the candidate
is absent from `package_identifiers_set_` and cover this ordering in the
regression test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]