diff options
-rw-r--r-- | lib/persistence.h | 3 | ||||
-rw-r--r-- | test/fixtures/json/bad/wrong_type.json | 5 |
2 files changed, 8 insertions, 0 deletions
diff --git a/lib/persistence.h b/lib/persistence.h index 5ef1400..86b0dce 100644 --- a/lib/persistence.h +++ b/lib/persistence.h @@ -196,14 +196,17 @@ namespace Persistence { auto no = Persistable::callSharedFactory(type); if (auto tno = std::dynamic_pointer_cast<T>(no)) { this->v = std::move(tno); + return; } } else { auto no = Persistable::callFactory(type); if (dynamic_cast<T *>(no.get())) { this->v.reset(static_cast<T *>(no.release())); + return; } } + throw std::runtime_error("Named type doesn't cast to target type"); } }; diff --git a/test/fixtures/json/bad/wrong_type.json b/test/fixtures/json/bad/wrong_type.json new file mode 100644 index 0000000..777d791 --- /dev/null +++ b/test/fixtures/json/bad/wrong_type.json @@ -0,0 +1,5 @@ +{ + "ptr": { + "@typeid": "SubObject" + } +} |