Commit a6c79fe3 authored by Dominik Charousset's avatar Dominik Charousset

Fix creating typed_actor from typed_actor_pointer

parent c1cded92
......@@ -5,6 +5,12 @@ is based on [Keep a Changelog](https://keepachangelog.com).
## [Unreleased]
### Fixed
- The handle type `typed_actor` now can construct from a `typed_actor_pointer`.
This resolves a compiler error when trying to initialize a handle for
`my_handle` from a self pointer of type `my_handle::pointer_view`.
## [0.18.0] - 2021-01-25
### Added
......
......@@ -137,7 +137,7 @@ public:
// Enable `handle_type{self}` for typed actor views.
template <class T, class = std::enable_if_t<
std::is_base_of<typed_actor_view_base, T>::value>>
explicit typed_actor(T ptr) : ptr_(ptr.internal_ptr()) {
explicit typed_actor(T ptr) : ptr_(ptr.ctrl()) {
static_assert(
detail::tl_subset_of<signatures, typename T::signatures>::value,
"Cannot assign T to incompatible handle type");
......
......@@ -85,6 +85,11 @@ public:
return view_.ctrl();
}
/// @private
actor_control_block* ctrl() const noexcept {
return view_.ctrl();
}
/// @private
scheduled_actor* internal_ptr() const noexcept {
return view_.internal_ptr();
......
......@@ -268,7 +268,6 @@ public:
actor_control_block* ctrl() const noexcept {
CAF_ASSERT(self_ != nullptr);
return actor_control_block::from(self_);
;
}
/// @private
......
......@@ -372,6 +372,34 @@ CAF_TEST(check_signature) {
run();
}
SCENARIO("state-classes may use typed pointers") {
GIVEN("a state class for a statically typed actor type") {
using foo_type = typed_actor<result<int32_t>(get_atom)>;
struct foo_state {
foo_state(foo_type::pointer_view selfptr) : self(selfptr) {
foo_type hdl{self};
CHECK_EQ(selfptr, actor_cast<abstract_actor*>(hdl));
foo_type hdl2{selfptr};
CHECK_EQ(hdl, hdl2);
}
foo_type::behavior_type make_behavior() {
return {
[](get_atom) { return int32_t{42}; },
};
}
foo_type::pointer_view self;
};
using foo_impl = stateful_actor<foo_state, foo_type::impl>;
WHEN("spawning a stateful actor using the state class") {
auto foo = sys.spawn<foo_impl>();
THEN("the actor calls make_behavior of the state class") {
inject((get_atom), from(self).to(foo).with(get_atom_v));
expect((int32_t), from(foo).to(self).with(42));
}
}
}
}
CAF_TEST_FIXTURE_SCOPE_END()
#endif // CAF_WINDOWS
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment