diff --git a/compiler/cpp/src/thrift/generate/t_go_generator.cc b/compiler/cpp/src/thrift/generate/t_go_generator.cc index 8bab9ae0650..3923c1f7694 100644 --- a/compiler/cpp/src/thrift/generate/t_go_generator.cc +++ b/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); + } + } + // This set is taken from https://github.com/golang/lint/blob/master/lint.go#L692 commonInitialisms.insert("API"); commonInitialisms.insert("ASCII"); diff --git a/lib/go/test/Makefile.am b/lib/go/test/Makefile.am index 00d022f76c0..cb93db160e4 100644 --- a/lib/go/test/Makefile.am +++ b/lib/go/test/Makefile.am @@ -72,7 +72,10 @@ gopath: $(THRIFT) $(THRIFTTEST) \ ValidateTest.thrift \ ForwardType.thrift \ StringParseAllocationTest.thrift \ - DocCommentTest.thrift + DocCommentTest.thrift \ + RemoteShadowClient.thrift \ + RemoteShadowHost.thrift \ + RemoteShadowTest.thrift mkdir -p gopath/src grep -v 'set' $(THRIFTTEST) > ThriftTest.thrift $(THRIFT) $(THRIFTARGS) $(RECURSIVE) @@ -115,6 +118,7 @@ gopath: $(THRIFT) $(THRIFTTEST) \ $(THRIFT) $(THRIFTARGS) ForwardType.thrift $(THRIFT) $(THRIFTARGS) StringParseAllocationTest.thrift $(THRIFT) $(THRIFTARGS) DocCommentTest.thrift + $(THRIFT) $(THRIFTARGS) -r RemoteShadowTest.thrift ln -nfs ../../tests gopath/src/tests cp -r ./dontexportrwtest gopath/src touch gopath @@ -149,7 +153,9 @@ check: gopath ./gopath/src/processormiddlewaretest \ ./gopath/src/clientmiddlewareexceptiontest \ ./gopath/src/validatetest \ - ./gopath/src/forwardtypetest + ./gopath/src/forwardtypetest \ + ./gopath/src/remoteshadowtest \ + ./gopath/src/remoteshadowtest/shadow_service-remote $(GO) test github.com/apache/thrift/lib/go/thrift $(GO) test ./gopath/src/tests ./gopath/src/dontexportrwtest @@ -200,6 +206,9 @@ EXTRA_DIST = \ OptionalFieldsTest.thrift \ ProcessorMiddlewareTest.thrift \ RefAnnotationFieldsTest.thrift \ + RemoteShadowClient.thrift \ + RemoteShadowHost.thrift \ + RemoteShadowTest.thrift \ RequiredFieldTest.thrift \ ServicesTest.thrift \ StringParseAllocationTest.thrift \ diff --git a/lib/go/test/RemoteShadowClient.thrift b/lib/go/test/RemoteShadowClient.thrift new file mode 100644 index 00000000000..e185bb70b18 --- /dev/null +++ b/lib/go/test/RemoteShadowClient.thrift @@ -0,0 +1,25 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +// Its Go package is named like a local variable of the generated -remote stub. +namespace go client + +struct Info { + 1: i32 x +} diff --git a/lib/go/test/RemoteShadowHost.thrift b/lib/go/test/RemoteShadowHost.thrift new file mode 100644 index 00000000000..5146ef0d31b --- /dev/null +++ b/lib/go/test/RemoteShadowHost.thrift @@ -0,0 +1,25 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +// Its Go package is named like a local variable of the generated -remote stub. +namespace go host + +struct Addr { + 1: string name +} diff --git a/lib/go/test/RemoteShadowTest.thrift b/lib/go/test/RemoteShadowTest.thrift new file mode 100644 index 00000000000..50580ccf012 --- /dev/null +++ b/lib/go/test/RemoteShadowTest.thrift @@ -0,0 +1,29 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +// The -remote stub declares local variables such as client and host; packages +// with those names, used by the arguments below, must not be shadowed by them. +namespace go remoteshadowtest + +include "RemoteShadowClient.thrift" +include "RemoteShadowHost.thrift" + +service ShadowService { + void f(1: RemoteShadowClient.Info info, 2: RemoteShadowHost.Addr addr) +}