[ 
https://issues.apache.org/jira/browse/THRIFT-6058?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Santiago Medina updated THRIFT-6058:
------------------------------------
    Description: 
Bug: Rust code generator produces incorrect deserialization code for 
list<UnionType> and set<UnionType> fields

The Rust code generator (t_rs_generator) is producing broken deserialization 
code when a struct contains a list<UnionType> or set<UnionType> field.

Affected code locations:
- t_rs_generator::render_list_sync_read (line 2016)
- t_rs_generator::render_set_sync_read (line 2051)

Incorrect code currently generated:

match UnionType::read_from_in_protocol(i_prot) {
    Ok(val) => \{ val.push(val); },
    ...
}

Two bugs:
1. Variable shadowing – the match binding "val" shadows the outer list/set 
variable "val", so val.push(val) tries to call push on the union value itself 
(which doesn't exist).
2. Missing Box::new() – the field type is Vec<Box<UnionType>> (or 
BTreeSet<Box<UnionType>>), but the code does not wrap the deserialized element 
in Box::new().

Correct code should be:

match UnionType::read_from_in_protocol(i_prot) {
    Ok(elem) => \{ val.push(Box::new(elem)); },
    ...
}

Note: The single-field deserialization path (render_struct_sync_read line 1718) 
correctly does the boxing, but the list/set collection paths do not.

Reproduction steps:
1. Create any .thrift file with a union type.
2. Use that union inside a list or set field in a struct.

Example .thrift:

union MyUnion {
  1: i32 int_value
  2: string string_value
}

struct MyStruct {
  3: optional list<MyUnion> items
  4: optional set<MyUnion> unique_items
}

This results in compilation errors in the generated Rust code.

> Rust codegen: `list<UnionType>` deserialization generates shadowed variable 
> and missing Box wrapping
> ----------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-6058
>                 URL: https://issues.apache.org/jira/browse/THRIFT-6058
>             Project: Thrift
>          Issue Type: Bug
>            Reporter: Santiago Medina
>            Priority: Major
>
> Bug: Rust code generator produces incorrect deserialization code for 
> list<UnionType> and set<UnionType> fields
> The Rust code generator (t_rs_generator) is producing broken deserialization 
> code when a struct contains a list<UnionType> or set<UnionType> field.
> Affected code locations:
> - t_rs_generator::render_list_sync_read (line 2016)
> - t_rs_generator::render_set_sync_read (line 2051)
> Incorrect code currently generated:
> match UnionType::read_from_in_protocol(i_prot) {
>     Ok(val) => \{ val.push(val); },
>     ...
> }
> Two bugs:
> 1. Variable shadowing – the match binding "val" shadows the outer list/set 
> variable "val", so val.push(val) tries to call push on the union value itself 
> (which doesn't exist).
> 2. Missing Box::new() – the field type is Vec<Box<UnionType>> (or 
> BTreeSet<Box<UnionType>>), but the code does not wrap the deserialized 
> element in Box::new().
> Correct code should be:
> match UnionType::read_from_in_protocol(i_prot) {
>     Ok(elem) => \{ val.push(Box::new(elem)); },
>     ...
> }
> Note: The single-field deserialization path (render_struct_sync_read line 
> 1718) correctly does the boxing, but the list/set collection paths do not.
> Reproduction steps:
> 1. Create any .thrift file with a union type.
> 2. Use that union inside a list or set field in a struct.
> Example .thrift:
> union MyUnion {
>   1: i32 int_value
>   2: string string_value
> }
> struct MyStruct {
>   3: optional list<MyUnion> items
>   4: optional set<MyUnion> unique_items
> }
> This results in compilation errors in the generated Rust code.



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

Reply via email to