[
https://issues.apache.org/jira/browse/THRIFT-6339?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Sylwester Lachiewicz updated THRIFT-6339:
-----------------------------------------
Description:
[t_kotlin_generator::generate_consts|https://github.com/apache/thrift/blob/master/compiler/cpp/src/thrift/generate/t_kotlin_generator.cc#L279]
tests {{is_base_type()}} and {{is_enum()}} on the constant's declared type
rather than on {{get_true_type()}}, so a constant whose type is a typedef
matches neither branch and is written without its value.
{code}
typedef i32 MyInt
const MyInt ANSWER = 42
{code}
{noformat}
$ thrift --gen kotlin -out kt repro.thrift && cat kt/reproConstants.kt
...
val ANSWER: kotlin.Int =
{noformat}
The generated file does not compile. The Java generator resolves the typedef
first; Kotlin should do the same. Reproduced on master at 3af0cfff1.
Out of scope here, and the same with or without a typedef: a {{uuid}} constant
takes the {{default:}} branch and is written as {{0}} ({{const uuid GEN_UUID}}
in {{test/ConstantsDemo.thrift}} already is), a {{binary}} constant is written
as a string literal for a {{kotlin.ByteArray}}, and container and struct
constants hit a {{// TODO}} and get no value. Those need a ticket of their own.
was:
[t_kotlin_generator::generate_consts|https://github.com/apache/thrift/blob/master/compiler/cpp/src/thrift/generate/t_kotlin_generator.cc#L279]
tests {{is_base_type()}} and {{is_enum()}} on the constant's declared type
rather than on {{get_true_type()}}, so a constant whose type is a typedef
matches neither branch and is written without its value.
{code}
typedef i32 MyInt
const MyInt ANSWER = 42
{code}
{noformat}
$ thrift --gen kotlin -out kt repro.thrift && cat kt/reproConstants.kt
...
val ANSWER: kotlin.Int =
{noformat}
The generated file does not compile. The Java generator resolves the typedef
first; Kotlin should do the same. Reproduced on master at 3af0cfff1.
> Kotlin generator emits a constant declared through a typedef with no value
> --------------------------------------------------------------------------
>
> Key: THRIFT-6339
> URL: https://issues.apache.org/jira/browse/THRIFT-6339
> Project: Thrift
> Issue Type: Bug
> Components: Kotlin - Compiler
> Affects Versions: 0.25.0
> Reporter: Sylwester Lachiewicz
> Priority: Major
>
> [t_kotlin_generator::generate_consts|https://github.com/apache/thrift/blob/master/compiler/cpp/src/thrift/generate/t_kotlin_generator.cc#L279]
> tests {{is_base_type()}} and {{is_enum()}} on the constant's declared type
> rather than on {{get_true_type()}}, so a constant whose type is a typedef
> matches neither branch and is written without its value.
> {code}
> typedef i32 MyInt
> const MyInt ANSWER = 42
> {code}
> {noformat}
> $ thrift --gen kotlin -out kt repro.thrift && cat kt/reproConstants.kt
> ...
> val ANSWER: kotlin.Int =
> {noformat}
> The generated file does not compile. The Java generator resolves the typedef
> first; Kotlin should do the same. Reproduced on master at 3af0cfff1.
> Out of scope here, and the same with or without a typedef: a {{uuid}}
> constant takes the {{default:}} branch and is written as {{0}} ({{const uuid
> GEN_UUID}} in {{test/ConstantsDemo.thrift}} already is), a {{binary}}
> constant is written as a string literal for a {{kotlin.ByteArray}}, and
> container and struct constants hit a {{// TODO}} and get no value. Those need
> a ticket of their own.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)