[ 
https://issues.apache.org/jira/browse/THRIFT-5801?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17870229#comment-17870229
 ] 

Yuxuan Wang commented on THRIFT-5801:
-------------------------------------

you are using optional field with default value. for go code, optional fields 
are generated as pointers, when they are not set they will be nil, and you can 
use the getters generated to get the value, when they are nil the getter will 
return the default values.

> Go does not handle the default value of list type correctly
> -----------------------------------------------------------
>
>                 Key: THRIFT-5801
>                 URL: https://issues.apache.org/jira/browse/THRIFT-5801
>             Project: Thrift
>          Issue Type: Bug
>          Components: Go - Compiler
>    Affects Versions: 0.19.0, 0.20.0
>            Reporter: Team_RPCtester
>            Priority: Major
>
> Hi,
> We discover an inconsistent behavior illustrated by the following example.
> {code:java}
> namespace go commonResourcestruct 
> StructClass_0 {
>   1: optional list<string, string> f_1 = ["a", "b"],
> }
> service DataService {
>     StructClass_0 Method_1(1: StructClass_0 agr_method_1)
> } {code}
> When default values are set for optional container type fields (e.g., lists, 
> sets), these fields are not automatically initialized in Go if not explicitly 
> set, whereas in other languages, these container type fields are 
> automatically initialized according to the default values. For example, in 
> the Go client side, our code are as follows:
> {code:java}
> agr_method_1_0 := commonResource.NewStructClass_0() 
> fmt.Println(agr_method_1_0) 
> // method_1_re_agr_method_1_0: StructClass_0({F_1:<nil>}) {code}
> In the Python client side:
> {code:java}
> agr_method_1 = StructClass_0()   
> print(agr_method_1)  
> # agr_method_1: StructClass_0(f_1-[’a’,’b’]) {code}
> In Go, the field f_1 is nil, while in Python, the field f_1 is automatically 
> set to its default value ['a', 'b'].
> Can you help check the issue?
> Thank you.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to