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

Todd Lipcon commented on THRIFT-4846:
-------------------------------------

Attached patch implements the sort and the failure for when the DAG is 
unsortable:

{code}
todd@todd-ThinkPad-P51:/src/thrift$ cat cycle.thrift 
struct A {
  1:B a_field;
}
struct B {
  1:A b_field;
}
todd@todd-ThinkPad-P51:/src/thrift$ ./compiler/cpp/thrift  -gen cpp 
cycle.thrift 
[WARNING:generation:1] Found cycle in structs: A.a_field -> B.b_field -> A
[WARNING:generation:1] Thrift file contains struct cycles, which may not be 
supported in all languages. Consider using reference fields. For example:
  1: Foo& my_field;

[FAILURE:generation:1] Cyclic references not supported by target language
{code}

> C++ generator should topologically sort struct definitions and error on cycles
> ------------------------------------------------------------------------------
>
>                 Key: THRIFT-4846
>                 URL: https://issues.apache.org/jira/browse/THRIFT-4846
>             Project: Thrift
>          Issue Type: Bug
>            Reporter: Todd Lipcon
>            Priority: Major
>         Attachments: thrift-4846.patch
>
>
> C++ (and maybe other languages?) treat Thrift struct-typed fields as plain 
> struct members of the containing struct. Currently, the generator outputs the 
> types in the same order as they're defined in the underlying Thrift field, 
> which means that a file like:
> {code}
> struct A {
>   1: B foo;
> }
> struct B {
> }
> {code}
> will generate C++ code that fails to compile.
> We should topologically-sort the structs before outputting the definitions so 
> that the generated code compiles correctly.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to