Skip to content

Commit

Permalink
Improved struct ordering (#1052)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenJKuhn authored Oct 28, 2021
1 parent eab5d4b commit bddd2e1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cppwinrt/code_writers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2718,9 +2718,11 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable<T, D, %>

auto depends = [](writer& w, complex_struct const& left, complex_struct const& right)
{
auto right_type = w.write_temp("%", right.type);
std::string right_as_ref = std::string("winrt::Windows::Foundation::IReference<") + right_type + ">";
for (auto&& field : left.fields)
{
if (w.write_temp("%", right.type) == field.second)
if (right_type == field.second || right_as_ref == field.second)
{
return true;
}
Expand Down
20 changes: 20 additions & 0 deletions test/test_component/test_component.idl
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,26 @@ namespace test_component
Int32 OuterValue;
};
}

// structs can contain nullable types (IReference<>) as well as strings. These are the only non-POD types
// Alphabetical sorting of names below is important to validate sort order in generated code. Metadata will
// sort to alphabetical order. cppwinrt needs to re-establish dependencies in the IReference types to produce
// correct output.
struct NullableC
{
Single a1;
Windows.Foundation.IReference<Single> a2;
};

struct NullableB
{
Windows.Foundation.IReference<NullableC> a1;
};

struct NullableA
{
Windows.Foundation.IReference<NullableB> a1;
};
}

namespace Parent
Expand Down

0 comments on commit bddd2e1

Please sign in to comment.