You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Andrii Degtiarov (JIRA)" <ji...@apache.org> on 2017/04/12 10:18:41 UTC
[jira] [Updated] (THRIFT-4173) Go: thrift compiler generates wrong
code for list of aliased type
[ https://issues.apache.org/jira/browse/THRIFT-4173?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Andrii Degtiarov updated THRIFT-4173:
-------------------------------------
Description:
Thrift code bellow produced incorrect Go code.
In the generated code {noformat}var _elem1 int8{noformat} should be {noformat}var _elem1 StatType{noformat} and {noformat}temp := int8(v){noformat} should be {noformat}temp := StatType(v){noformat}
Thrift:
{code}
typedef i8 StatType
struct SomeStruct {
1: list<StatType> stats;
}
{code}
Generated code:
{code:go}
func (p *CSVAnalyzeTaskPayload) ReadField1(iprot thrift.TProtocol) error {
_, size, err := iprot.ReadListBegin()
if err != nil {
return thrift.PrependError("error reading list begin: ", err)
}
tSlice := make([]StatType, 0, size)
p.Stats = tSlice
for i := 0; i < size; i ++ {
var _elem1 int8
if v, err := iprot.ReadByte(); err != nil {
return thrift.PrependError("error reading field 0: ", err)
} else {
temp := int8(v)
_elem1 = temp
}
p.Stats = append(p.Stats, _elem1)
}
if err := iprot.ReadListEnd(); err != nil {
return thrift.PrependError("error reading list end: ", err)
}
return nil
}
{code}
was:
Thrift code bellow produced incorrect Go code.
In the generated code {noformat}var _elem1 int8{noformat} should be {noformat}var _elem1 StatType{noformat} and {noformat}temp := int8(v){noformat} should be {noformat}temp := StatType(v){noformat}
Thrift:
{code:thrift}
typedef i8 StatType
struct SomeStruct {
1: list<StatType> stats;
}
{code}
Generated code:
{code:go}
func (p *CSVAnalyzeTaskPayload) ReadField1(iprot thrift.TProtocol) error {
_, size, err := iprot.ReadListBegin()
if err != nil {
return thrift.PrependError("error reading list begin: ", err)
}
tSlice := make([]StatType, 0, size)
p.Stats = tSlice
for i := 0; i < size; i ++ {
var _elem1 int8
if v, err := iprot.ReadByte(); err != nil {
return thrift.PrependError("error reading field 0: ", err)
} else {
temp := int8(v)
_elem1 = temp
}
p.Stats = append(p.Stats, _elem1)
}
if err := iprot.ReadListEnd(); err != nil {
return thrift.PrependError("error reading list end: ", err)
}
return nil
}
{code}
> Go: thrift compiler generates wrong code for list of aliased type
> ------------------------------------------------------------------
>
> Key: THRIFT-4173
> URL: https://issues.apache.org/jira/browse/THRIFT-4173
> Project: Thrift
> Issue Type: Bug
> Components: Compiler (General)
> Affects Versions: 0.10.0
> Environment: Linux amd64/Mac OS Sierra
> Reporter: Andrii Degtiarov
>
> Thrift code bellow produced incorrect Go code.
> In the generated code {noformat}var _elem1 int8{noformat} should be {noformat}var _elem1 StatType{noformat} and {noformat}temp := int8(v){noformat} should be {noformat}temp := StatType(v){noformat}
> Thrift:
> {code}
> typedef i8 StatType
> struct SomeStruct {
> 1: list<StatType> stats;
> }
> {code}
> Generated code:
> {code:go}
> func (p *CSVAnalyzeTaskPayload) ReadField1(iprot thrift.TProtocol) error {
> _, size, err := iprot.ReadListBegin()
> if err != nil {
> return thrift.PrependError("error reading list begin: ", err)
> }
> tSlice := make([]StatType, 0, size)
> p.Stats = tSlice
> for i := 0; i < size; i ++ {
> var _elem1 int8
> if v, err := iprot.ReadByte(); err != nil {
> return thrift.PrependError("error reading field 0: ", err)
> } else {
> temp := int8(v)
> _elem1 = temp
> }
> p.Stats = append(p.Stats, _elem1)
> }
> if err := iprot.ReadListEnd(); err != nil {
> return thrift.PrependError("error reading list end: ", err)
> }
> return nil
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)