Skip to content

Commit

Permalink
Improve error message when patching cpp.ref type
Browse files Browse the repository at this point in the history
Summary:
Currently cpp.ref type is already unsupported; this diff makes the error message more obvious.

While in the future we can support patching cpp.ref type, we should ask them try to migrate to thrift.box first, since cpp.ref is deprecated.

Reviewed By: vitaut

Differential Revision: D47195678

fbshipit-source-id: fc66096aa60560c189dec3b53e395906b39fc060
  • Loading branch information
TJ Yin authored and facebook-github-bot committed Jul 6, 2023
1 parent 4739c25 commit 123488e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions thrift/lib/cpp2/op/detail/StructPatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,24 @@ class StructPatch : public BaseEnsurePatch<Patch, StructPatch<Patch>> {
}
}

~StructPatch() {
if (false) {
// Implement this check in destructor to make sure it's instantiated.
op::for_each_ordinal<T>([](auto id) {
static_assert(
!apache::thrift::detail::is_shared_or_unique_ptr_v<
op::get_field_ref<T, decltype(id)>>,
"Patching cpp.ref field is unsupported since we cannot distinguish "
"unqualified and optional fields. Why? The type of `foo.field()` "
"is `std::unique_ptr` regardless Whether field is optional or "
"unqualified. In addition, Thrift Patch has different behavior "
"between optional and unqualified fields, e.g. `PatchOp::Clear` "
"will clear an optional field, but set an unqualified field to the "
"intrinsic default.");
});
}
}

private:
using Base::data_;
};
Expand Down

0 comments on commit 123488e

Please sign in to comment.