diff options
author | Jens Geyer <jensg@apache.org> | 2020-12-04 01:18:54 +0100 |
---|---|---|
committer | Jens Geyer <jensg@apache.org> | 2020-12-04 21:05:43 +0100 |
commit | 12f6c31c8df739ccff271c8b81345d9a630c8921 (patch) | |
tree | 7801912379a3c675460763b4da4142f3215b29b2 | |
parent | 66777ad21551d5d2f213fe06b53336988fe29136 (diff) | |
download | thrift-12f6c31c8df739ccff271c8b81345d9a630c8921.tar.gz |
THRIFT-5320: Usage of "Task" as IDL identifier generates uncompileable code
Client: netstd
Patch: Jens Geyer
This closes #2289
6 files changed, 130 insertions, 9 deletions
diff --git a/compiler/cpp/src/thrift/generate/t_netstd_generator.cc b/compiler/cpp/src/thrift/generate/t_netstd_generator.cc index 45e658e82..ea4778287 100644 --- a/compiler/cpp/src/thrift/generate/t_netstd_generator.cc +++ b/compiler/cpp/src/thrift/generate/t_netstd_generator.cc @@ -1198,7 +1198,7 @@ void t_netstd_generator::generate_netstd_deepcopy_method(ostream& out, t_struct* void t_netstd_generator::generate_netstd_struct_reader(ostream& out, t_struct* tstruct) { - out << indent() << "public async Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)" << endl + out << indent() << "public async global::System.Threading.Tasks.Task ReadAsync(TProtocol iprot, CancellationToken cancellationToken)" << endl << indent() << "{" << endl; indent_up(); out << indent() << "iprot.IncrementRecursionDepth();" << endl @@ -1340,7 +1340,7 @@ void t_netstd_generator::generate_null_check_end(ostream& out, t_field* tfield) void t_netstd_generator::generate_netstd_struct_writer(ostream& out, t_struct* tstruct) { - out << indent() << "public async Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)" << endl + out << indent() << "public async global::System.Threading.Tasks.Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)" << endl << indent() << "{" << endl; indent_up(); @@ -1390,7 +1390,7 @@ void t_netstd_generator::generate_netstd_struct_writer(ostream& out, t_struct* t void t_netstd_generator::generate_netstd_struct_result_writer(ostream& out, t_struct* tstruct) { - out << indent() << "public async Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)" << endl + out << indent() << "public async global::System.Threading.Tasks.Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)" << endl << indent() << "{" << endl; indent_up(); @@ -1549,7 +1549,7 @@ void t_netstd_generator::generate_netstd_union_definition(ostream& out, t_struct out << indent() << "{" << endl; indent_up(); - out << indent() << "public abstract Task WriteAsync(TProtocol tProtocol, CancellationToken cancellationToken);" << endl + out << indent() << "public abstract global::System.Threading.Tasks.Task WriteAsync(TProtocol tProtocol, CancellationToken cancellationToken);" << endl << indent() << "public readonly int Isset;" << endl << indent() << "public abstract object Data { get; }" << endl << indent() << "protected " << tunion->get_name() << "(int isset)" << endl @@ -1659,7 +1659,7 @@ void t_netstd_generator::generate_netstd_union_definition(ostream& out, t_struct generate_netstd_struct_equals(out, &undefined_struct); generate_netstd_struct_hashcode(out, &undefined_struct); - out << indent() << "public override Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)" << endl + out << indent() << "public override global::System.Threading.Tasks.Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken)" << endl << indent() << "{" << endl; indent_up(); out << indent() << "throw new TProtocolException( TProtocolException.INVALID_DATA, \"Cannot persist an union type which is not set.\");" << endl; @@ -1738,7 +1738,7 @@ void t_netstd_generator::generate_netstd_union_class(ostream& out, t_struct* tun indent_down(); out << indent() << "}" << endl << endl; - out << indent() << "public override async Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken) {" << endl; + out << indent() << "public override async global::System.Threading.Tasks.Task WriteAsync(TProtocol oprot, CancellationToken cancellationToken) {" << endl; indent_up(); out << indent() << "oprot.IncrementRecursionDepth();" << endl @@ -2162,7 +2162,7 @@ void t_netstd_generator::generate_service_server(ostream& out, t_service* tservi if (extends.empty()) { - out << indent() << "protected delegate Task ProcessFunction(int seqid, TProtocol iprot, TProtocol oprot, CancellationToken cancellationToken);" << endl; + out << indent() << "protected delegate global::System.Threading.Tasks.Task ProcessFunction(int seqid, TProtocol iprot, TProtocol oprot, CancellationToken cancellationToken);" << endl; } if (extends.empty()) @@ -2271,7 +2271,7 @@ void t_netstd_generator::generate_function_helpers(ostream& out, t_function* tfu void t_netstd_generator::generate_process_function_async(ostream& out, t_service* tservice, t_function* tfunction) { (void)tservice; - out << indent() << "public async Task " << tfunction->get_name() + out << indent() << "public async global::System.Threading.Tasks.Task " << tfunction->get_name() << "_ProcessAsync(int seqid, TProtocol iprot, TProtocol oprot, CancellationToken cancellationToken)" << endl << indent() << "{" << endl; indent_up(); @@ -3262,7 +3262,7 @@ string t_netstd_generator::function_signature(t_function* tfunction, string pref string t_netstd_generator::function_signature_async(t_function* tfunction, string prefix) { t_type* ttype = tfunction->get_returntype(); - string task = "Task"; + string task = "global::System.Threading.Tasks.Task"; if (!ttype->is_void()) { task += "<" + type_name(ttype) + ">"; diff --git a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift.PublicInterfaces.Compile.Tests.csproj b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift.PublicInterfaces.Compile.Tests.csproj index 95c85afc0..c43c71cd7 100644 --- a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift.PublicInterfaces.Compile.Tests.csproj +++ b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift.PublicInterfaces.Compile.Tests.csproj @@ -55,6 +55,9 @@ <Exec Condition="Exists('$(PathToThrift)')" Command="$(PathToThrift) -gen netstd:wcf,union,serial -r ./Thrift5253.thrift" /> <Exec Condition="Exists('thrift')" Command="thrift -gen netstd:wcf,union,serial -r ./Thrift5253.thrift" /> <Exec Condition="Exists('$(ProjectDir)/../../../../compiler/cpp/thrift')" Command="$(ProjectDir)/../../../../compiler/cpp/thrift -gen netstd:wcf,union,serial -r ./Thrift5253.thrift" /> + <Exec Condition="Exists('$(PathToThrift)')" Command="$(PathToThrift) -gen netstd:wcf,union,serial -r ./Thrift5320.thrift" /> + <Exec Condition="Exists('thrift')" Command="thrift -gen netstd:wcf,union,serial -r ./Thrift5320.thrift" /> + <Exec Condition="Exists('$(ProjectDir)/../../../../compiler/cpp/thrift')" Command="$(ProjectDir)/../../../../compiler/cpp/thrift -gen netstd:wcf,union,serial -r ./Thrift5320.thrift" /> </Target> </Project> diff --git a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5320.enum.thrift b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5320.enum.thrift new file mode 100644 index 000000000..d4392d6a8 --- /dev/null +++ b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5320.enum.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. + +// Testcase for THRIFT-5320 Usage of "Task" as IDL identifier generates uncompileable code + +namespace * Thrift5320.enums + +enum Task { + Zero, + More +} + diff --git a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5320.exception.thrift b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5320.exception.thrift new file mode 100644 index 000000000..b6b8cdab1 --- /dev/null +++ b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5320.exception.thrift @@ -0,0 +1,27 @@ +# 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. + +// Testcase for THRIFT-5320 Usage of "Task" as IDL identifier generates uncompileable code + +namespace * Thrift5320.exceptions + + + +exception Task { + 1: Task left + 2: Task right +} + diff --git a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5320.struct.thrift b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5320.struct.thrift new file mode 100644 index 000000000..771c48702 --- /dev/null +++ b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5320.struct.thrift @@ -0,0 +1,26 @@ +# 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. + +// Testcase for THRIFT-5320 Usage of "Task" as IDL identifier generates uncompileable code + +namespace * Thrift5320.structs + + +struct Task { + 1: Task left + 2: Task right +} + diff --git a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5320.thrift b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5320.thrift new file mode 100644 index 000000000..f677973b0 --- /dev/null +++ b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift5320.thrift @@ -0,0 +1,40 @@ +# 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. + +// Testcase for THRIFT-5320 Usage of "Task" as IDL identifier generates uncompileable code + +namespace * Thrift5320.Task + +include "Thrift5320.enum.thrift" +include "Thrift5320.exception.thrift" +include "Thrift5320.struct.thrift" + +enum Foobar { + Task = 0 +} + + +service Task { + Thrift5320.enum.Task Task( + 1 : Thrift5320.struct.Task foo, + 2: Foobar bar + ) throws ( + 1: Thrift5320.exception.Task error + ) +} + + + |