You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@thrift.apache.org by "slachiewicz (via GitHub)" <gi...@apache.org> on 2026/09/23 06:27:56 UTC
[PR] THRIFT-6339: Resolve typedefs before rendering a Kotlin constant [thrift]
slachiewicz opened a new pull request, #3938:
URL: https://github.com/apache/thrift/pull/3938
`generate_consts` tested the declared type, so a constant declared through a typedef got neither `const` nor a value (`val ANSWER: kotlin.Int = `). It now resolves the typedef first, as the Java generator does.
Not in this PR, and the same with or without a typedef: `uuid` constants render as `0`, `binary` ones as a string literal, and container and struct constants still get no value (the `// TODO` branch).
Verified: `--gen kotlin` over every `.thrift` in the repository → only the typedef constants in the two `ConstantsDemo.thrift` files change.
- [x] Did you create an [Apache Jira](https://issues.apache.org/jira/projects/THRIFT/issues/) ticket? [THRIFT-6339](https://issues.apache.org/jira/browse/THRIFT-6339)
- [x] If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
- [x] Did you squash your changes to a single commit?
- [x] Did you do your best to avoid breaking changes? No: the affected files did not compile.
- [x] Code change, so the commit carries no CI-skip marker.
- [x] Tests: `compiler/cpp/tests/kotlin/t_kotlin_generator_const_tests.cc`, which fails without the fix; kotlin generator tests are switched on.
- [x] AI-assisted: the commit carries a `Co-Authored-By:` trailer. No new dependency or third-party code.
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] THRIFT-6339: Resolve typedefs before rendering a Kotlin constant [thrift]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #3938:
URL: https://github.com/apache/thrift/pull/3938#discussion_r4152138763
##########
compiler/cpp/tests/kotlin/t_kotlin_generator_const_tests.cc:
##########
@@ -0,0 +1,67 @@
+// 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.
+
+#include "../cpp/t_cpp_generator_test_utils.h"
+
+#include <cstdio>
+#include <fstream>
+#include <memory>
+
+using std::map;
+using std::string;
+using cpp_generator_test_utils::parse_thrift_for_test;
+using cpp_generator_test_utils::read_file;
+
+// THRIFT-6339: generate_consts tested the declared type, so a constant of a
+// typedef type matched neither the base-type nor the enum branch and was
+// written without a value.
+TEST_CASE("t_kotlin_generator renders a constant declared through a typedef", "[functional]")
+{
+ const string thrift_path = "test_kotlin_const.thrift";
+ const string thrift_source =
+ "typedef i32 MyInt\n"
+ "const MyInt ANSWER = 42\n"
+ "enum E { A = 1 }\n"
+ "typedef E MyE\n"
+ "const MyE FIRST = E.A\n"
+ "const i32 PLAIN = 7\n";
+
+ {
+ std::ofstream thrift_file(thrift_path, std::ios::binary);
+ REQUIRE(thrift_file.is_open());
+ thrift_file << thrift_source;
+ }
+
+ map<string, string> parsed_options;
+ std::unique_ptr<t_program> program(new t_program(thrift_path, "test_kotlin_const"));
+ parse_thrift_for_test(program.get());
+
+ std::unique_ptr<t_generator> gen(
+ t_generator_registry::get_generator(program.get(), "kotlin", parsed_options, ""));
+ REQUIRE(gen != nullptr);
+ REQUIRE_NOTHROW(gen->generate_program());
+
+ const string generated = read_file("test_kotlin_constConstants.kt");
+ REQUIRE(!generated.empty());
+ REQUIRE(generated.find("val ANSWER: kotlin.Int = 42\n") != string::npos);
Review Comment:
This assertion starts at `val`, so it still passes if typedef-backed primitive constants lose the `const` modifier again. Since restoring `const` is one of the two behaviors fixed here, assert the complete declaration.
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] THRIFT-6339: Resolve typedefs before rendering a Kotlin constant [thrift]
Posted by "Jens-G (via GitHub)" <gi...@apache.org>.
Jens-G commented on PR #3938:
URL: https://github.com/apache/thrift/pull/3938#issuecomment-5846793828
### Code review
No issues found. Checked for bugs and CLAUDE.md compliance.
🤖 Generated with [Claude Code](https://claude.ai/code)
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] THRIFT-6339: Resolve typedefs before rendering a Kotlin constant [thrift]
Posted by "slachiewicz (via GitHub)" <gi...@apache.org>.
slachiewicz commented on PR #3938:
URL: https://github.com/apache/thrift/pull/3938#issuecomment-6426373972
The test now matches the full declaration (`const val ANSWER: kotlin.Int = 42`), so it fails if `const` goes missing again. I'll mark it ready once CI is green.
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] THRIFT-6339: Resolve typedefs before rendering a Kotlin constant [thrift]
Posted by "Jens-G (via GitHub)" <gi...@apache.org>.
Jens-G merged PR #3938:
URL: https://github.com/apache/thrift/pull/3938
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] THRIFT-6339: Resolve typedefs before rendering a Kotlin constant [thrift]
Posted by "slachiewicz (via GitHub)" <gi...@apache.org>.
slachiewicz commented on code in PR #3938:
URL: https://github.com/apache/thrift/pull/3938#discussion_r4382023447
##########
compiler/cpp/tests/kotlin/t_kotlin_generator_const_tests.cc:
##########
@@ -0,0 +1,67 @@
+// 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.
+
+#include "../cpp/t_cpp_generator_test_utils.h"
+
+#include <cstdio>
+#include <fstream>
+#include <memory>
+
+using std::map;
+using std::string;
+using cpp_generator_test_utils::parse_thrift_for_test;
+using cpp_generator_test_utils::read_file;
+
+// THRIFT-6339: generate_consts tested the declared type, so a constant of a
+// typedef type matched neither the base-type nor the enum branch and was
+// written without a value.
+TEST_CASE("t_kotlin_generator renders a constant declared through a typedef", "[functional]")
+{
+ const string thrift_path = "test_kotlin_const.thrift";
+ const string thrift_source =
+ "typedef i32 MyInt\n"
+ "const MyInt ANSWER = 42\n"
+ "enum E { A = 1 }\n"
+ "typedef E MyE\n"
+ "const MyE FIRST = E.A\n"
+ "const i32 PLAIN = 7\n";
+
+ {
+ std::ofstream thrift_file(thrift_path, std::ios::binary);
+ REQUIRE(thrift_file.is_open());
+ thrift_file << thrift_source;
+ }
+
+ map<string, string> parsed_options;
+ std::unique_ptr<t_program> program(new t_program(thrift_path, "test_kotlin_const"));
+ parse_thrift_for_test(program.get());
+
+ std::unique_ptr<t_generator> gen(
+ t_generator_registry::get_generator(program.get(), "kotlin", parsed_options, ""));
+ REQUIRE(gen != nullptr);
+ REQUIRE_NOTHROW(gen->generate_program());
+
+ const string generated = read_file("test_kotlin_constConstants.kt");
+ REQUIRE(!generated.empty());
+ REQUIRE(generated.find("val ANSWER: kotlin.Int = 42\n") != string::npos);
Review Comment:
Fixed in the updated commit.
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] THRIFT-6339: Resolve typedefs before rendering a Kotlin constant [thrift]
Posted by "Jens-G (via GitHub)" <gi...@apache.org>.
Jens-G commented on PR #3938:
URL: https://github.com/apache/thrift/pull/3938#issuecomment-6261671374
@slachiewicz and here?
--
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: notifications-unsubscribe@thrift.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org