You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Jens Geyer (JIRA)" <ji...@apache.org> on 2017/07/17 21:26:00 UTC

[jira] [Comment Edited] (THRIFT-4253) Go generator assigns strings to field in const instead of pointers.

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

Jens Geyer edited comment on THRIFT-4253 at 7/17/17 9:25 PM:
-------------------------------------------------------------

Confirmed, trying this ends up in a "{{cannot use "test" (type string) as type *string in field value}}". 

That seems absolutely wrong, and besides fixing it we also should integrate an test into [ConstantsDemo.thrift|https://git-wip-us.apache.org/repos/asf?p=thrift.git;a=blob;f=test/ConstantsDemo.thrift;hb=HEAD]

[~DavinC], what specific questions that I can answer do you have?


was (Author: jensg):
Confirmed, trying this ends up in a "{{cannot use "test" (type string) as type *string in field value}}". 

That seems absolutely wrong, and besides fixing it we also should integrate an test into [ConstantsDemo.thrift|https://git-wip-us.apache.org/repos/asf?p=thrift.git;a=blob;f=test/ConstantsDemo.thrift;hb=HEAD]

> Go generator assigns strings to field in const instead of pointers.
> -------------------------------------------------------------------
>
>                 Key: THRIFT-4253
>                 URL: https://issues.apache.org/jira/browse/THRIFT-4253
>             Project: Thrift
>          Issue Type: Bug
>          Components: Go - Compiler
>    Affects Versions: 0.10.0
>         Environment: Generated using docker-thrift.
>            Reporter: Davin Chia
>
> Given the follow thrift definition:
> {code:java}
> struct custom {
>   1: required string field_a;
>   2: optional string field_b;
> }
> {code}
> with the following constant map defined in the same file:
> {code:java}
> const map<i32, custom> custom_map = {
>   ...,
>   42 : { 'field_a':'www.testa.com', 'field_b':'www.testb.com'},
>   ...,
> }
> {code}
> Thrift generates the following go struct in the main {code:java}x.go{code} file:
> {code:java}
> type Custom struct {
>   FieldA string `thrift:"field_a,required" db:"field_a" json:"field_a"`
>   FieldB *string `thrift:"field_b,2" db:"field_b" json:"field_b,omitempty"`
> }
> {code}
> with the corresponding assignments in the {code:java} X-consts.go {code} file:
> {code:java}
> CUSTOM_MAP = map[int]*Custom {
>   ...,
>   42: &Custom {FieldA: "www.testa.com", FieldB: "www.testb.com"},
>   ...,
> }
> {code}
> I assume field_b's pointer type is to allow for null values as per the optional. The generator should be assigning pointers instead of strings. 
> I'm not sure how much effort it would take to fix this. I am encountering this problem at work right and would be very happy to starting working on this with some guidance from experts around here. 



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)