From bddd2e1303ecdf4c26e4721cc6b66a58b37d9949 Mon Sep 17 00:00:00 2001 From: Ben Kuhn Date: Thu, 28 Oct 2021 15:42:43 -0700 Subject: [PATCH] Improved struct ordering (#1052) --- cppwinrt/code_writers.h | 4 +++- test/test_component/test_component.idl | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/cppwinrt/code_writers.h b/cppwinrt/code_writers.h index da54d62e4..c369eb98c 100644 --- a/cppwinrt/code_writers.h +++ b/cppwinrt/code_writers.h @@ -2718,9 +2718,11 @@ struct __declspec(empty_bases) produce_dispatch_to_overridable 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; } diff --git a/test/test_component/test_component.idl b/test/test_component/test_component.idl index 9ff4b8ec0..31043c7e4 100644 --- a/test/test_component/test_component.idl +++ b/test/test_component/test_component.idl @@ -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 a2; + }; + + struct NullableB + { + Windows.Foundation.IReference a1; + }; + + struct NullableA + { + Windows.Foundation.IReference a1; + }; } namespace Parent