Jens Geyer created THRIFT-5998:
----------------------------------
Summary: netstd generator: duplicate DeepCopy/Equals/GetHashCode
extension methods when IDL includes other IDL files
Key: THRIFT-5998
URL: https://issues.apache.org/jira/browse/THRIFT-5998
Project: Thrift
Issue Type: Bug
Components: netstd - Compiler
Reporter: Jens Geyer
When an IDL file A includes file B and uses types from B in container fields
(e.g. {{map<string, B.Foo>}} or {{list<B.Foo>}}), the netstd generator produces
identical extension method signatures in both the generated {{A.Extensions.cs}}
and {{B.Extensions.cs}}. The C# compiler then raises CS0121 ("ambiguous call")
at every call site that invokes those extension methods.
Root cause: {{collect_extensions_types(t_type* ttype)}} recursively walks into
structs from included programs to discover nested container types. This causes
container types that are internal to the included program's structs to be
registered in the current program's {{collected_extension_types}} map,
resulting in duplicate extension method declarations.
For example, if {{B.thrift}} defines struct {{Foo}} with a {{map<double, Bar>}}
field, and {{A.thrift}} includes B and uses {{Foo}} as a field value, the
generator emits {{DeepCopy(this Dictionary<double, Bar>?)}} in both
{{A.Extensions.cs}} and {{B.Extensions.cs}}.
Fix: in {{collect_extensions_types(t_type* ttype)}}, when processing a struct
that belongs to an included program ({{ttype->get_program() != program_}}),
skip the recursive field walk. The included program's own generator run is
responsible for discovering and emitting extension methods for that struct's
internal container types.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)