From dca42ab4b521bd4b0ffda67ae47a75b47045af24 Mon Sep 17 00:00:00 2001 From: Yuxuan 'fishy' Wang Date: Wed, 15 Feb 2023 12:19:44 -0800 Subject: THRIFT-5685: Revert "THRIFT-5601: Fix forward typedef in go compiler" This reverts commit b39370ec3bc96d201bbc82fbde136f98ae605ed1, and also adds a test case for THRIFT-5685. --- lib/go/test/ForwardType.thrift | 30 +++++++++++++++++++++++++ lib/go/test/ForwardTypedef.thrift | 33 ---------------------------- lib/go/test/Makefile.am | 7 +++--- lib/go/test/tests/forwardtype_test.go | 41 +++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 36 deletions(-) create mode 100644 lib/go/test/ForwardType.thrift delete mode 100644 lib/go/test/ForwardTypedef.thrift create mode 100644 lib/go/test/tests/forwardtype_test.go (limited to 'lib') diff --git a/lib/go/test/ForwardType.thrift b/lib/go/test/ForwardType.thrift new file mode 100644 index 000000000..0433c97cf --- /dev/null +++ b/lib/go/test/ForwardType.thrift @@ -0,0 +1,30 @@ +/* + * 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. + */ + +// https://issues.apache.org/jira/browse/THRIFT-5685 + +namespace go forwardtypetest + +struct Struct { + 1: optional Exc foo +} + +exception Exc { + 1: optional i32 code +} diff --git a/lib/go/test/ForwardTypedef.thrift b/lib/go/test/ForwardTypedef.thrift deleted file mode 100644 index 4266b7a28..000000000 --- a/lib/go/test/ForwardTypedef.thrift +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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. - */ - -// https://issues.apache.org/jira/browse/THRIFT-5601 - -namespace go forwardtypedef - -struct Struct { - 1: optional Def foo - 2: optional Exc bar -} - -typedef i32 Def - -exception Exc { - 1: optional i32 code -} diff --git a/lib/go/test/Makefile.am b/lib/go/test/Makefile.am index c255a8e48..cb8928bc8 100644 --- a/lib/go/test/Makefile.am +++ b/lib/go/test/Makefile.am @@ -62,7 +62,7 @@ gopath: $(THRIFT) $(THRIFTTEST) \ ProcessorMiddlewareTest.thrift \ ClientMiddlewareExceptionTest.thrift \ ValidateTest.thrift \ - ForwardTypedef.thrift + ForwardType.thrift mkdir -p gopath/src grep -v list.*map.*list.*map $(THRIFTTEST) | grep -v 'set' > ThriftTest.thrift $(THRIFT) $(THRIFTARGS) -r IncludesTest.thrift @@ -97,7 +97,7 @@ gopath: $(THRIFT) $(THRIFTTEST) \ $(THRIFT) $(THRIFTARGS_SKIP_REMOTE) ProcessorMiddlewareTest.thrift $(THRIFT) $(THRIFTARGS) ClientMiddlewareExceptionTest.thrift $(THRIFT) $(THRIFTARGS) ValidateTest.thrift - $(THRIFT) $(THRIFTARGS) ForwardTypedef.thrift + $(THRIFT) $(THRIFTARGS) ForwardType.thrift ln -nfs ../../tests gopath/src/tests cp -r ./dontexportrwtest gopath/src touch gopath @@ -124,7 +124,7 @@ check: gopath ./gopath/src/processormiddlewaretest \ ./gopath/src/clientmiddlewareexceptiontest \ ./gopath/src/validatetest \ - ./gopath/src/forwardtypedef + ./gopath/src/forwardtypetest $(GO) test github.com/apache/thrift/lib/go/thrift $(GO) test ./gopath/src/tests ./gopath/src/dontexportrwtest @@ -155,6 +155,7 @@ EXTRA_DIST = \ DuplicateImportsTest.thrift \ ErrorTest.thrift \ EqualsTest.thrift \ + ForwardType.thrift \ GoTagTest.thrift \ IgnoreInitialismsTest.thrift \ IncludesTest.thrift \ diff --git a/lib/go/test/tests/forwardtype_test.go b/lib/go/test/tests/forwardtype_test.go new file mode 100644 index 000000000..99b7890e6 --- /dev/null +++ b/lib/go/test/tests/forwardtype_test.go @@ -0,0 +1,41 @@ +/* + * 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. + */ + +package tests + +import ( + "testing" + + "github.com/apache/thrift/lib/go/test/gopath/src/forwardtypetest" + "github.com/apache/thrift/lib/go/thrift" +) + +func TestForwardType(t *testing.T) { + // See https://issues.apache.org/jira/browse/THRIFT-5685 + + const code = int32(1) + foo := &forwardtypetest.Struct{ + Foo: &forwardtypetest.Exc{ + Code: thrift.Pointer(code), + }, + } + if got, want := foo.GetFoo().GetCode(), code; got != want { + t.Errorf("code got %v want %v", got, want) + } +} -- cgit v1.2.1