diff --git a/nyan/nyan_tool.cpp b/nyan/nyan_tool.cpp index 4d0ecee..d691160 100644 --- a/nyan/nyan_tool.cpp +++ b/nyan/nyan_tool.cpp @@ -27,6 +27,7 @@ int test_parser(const std::string &base_path, const std::string &filename) { std::shared_ptr root = db->new_view(); + Object test = root->get_object("test.Test"); Object second = root->get_object("test.Second"); Object first = root->get_object("test.First"); @@ -34,10 +35,9 @@ int test_parser(const std::string &base_path, const std::string &filename) { << *root->get_object("test.First").get("member") << std::endl; - std::optional> optional_wat3 = first.get_optional("wat3", 0); - - if (optional_wat3.has_value()) { - if ((*optional_wat3)->get_name() != "test.Second") { + std::optional> wat3_first = first.get_optional("wat3", 0); + if (wat3_first.has_value()) { + if ((*wat3_first)->get_name() != "test.Second") { std::cout << "First.wat3 has wrong value at t=0" << std::endl; return 1; } @@ -47,6 +47,19 @@ int test_parser(const std::string &base_path, const std::string &filename) { return 1; } + std::optional> wat3_second = second.get_optional("wat3", 0); + if (wat3_second.has_value()) { + std::cout << "Second.wat3 should be None" << std::endl; + return 1; + } + + std::optional> wat3_test = test.get_optional("wat3", 0); + if (wat3_test.has_value()) { + std::cout << "Test.wat3 should be None" << std::endl; + return 1; + } + + Object patch = root->get_object("test.FirstPatch"); for (int i = 0; i < 3; i++) { Transaction tx = root->new_transaction(); @@ -56,8 +69,8 @@ int test_parser(const std::string &base_path, const std::string &filename) { } } - optional_wat3 = first.get_optional("wat3"); - if (optional_wat3.has_value()) { + wat3_first = first.get_optional("wat3"); + if (wat3_first.has_value()) { std::cout << "First.wat3 should be None by patch" << std::endl; return 1; } @@ -250,7 +263,6 @@ std::pair argparse(int argc, char** argv) { int main(int argc, char **argv) { - auto args = nyan::argparse(argc, argv); nyan::flags_t flags = args.first; nyan::params_t params = args.second; diff --git a/nyan/object.cpp b/nyan/object.cpp index b73bdd1..f0d102e 100644 --- a/nyan/object.cpp +++ b/nyan/object.cpp @@ -1,4 +1,4 @@ -// Copyright 2016-2023 the nyan authors, LGPLv3+. See copying.md for legal info. +// Copyright 2016-2024 the nyan authors, LGPLv3+. See copying.md for legal info. #include "object.h" @@ -170,15 +170,16 @@ ValueHolder Object::calculate_value(const memberid_t &member, order_t t) const { ValueHolder result = base_value->copy(); // walk back and apply the value changes - while (true) { - const Member *change = parents[defined_by]->get(member); + + // skip the parent that assigns the value + // this prevents reassignment errors e.g. from assigning None + int parent_idx = defined_by - 1; + while (parent_idx >= 0) { + const Member *change = parents[parent_idx]->get(member); if (change != nullptr) { result->apply(*change); } - if (defined_by == 0) { - break; - } - defined_by -= 1; + parent_idx -= 1; } return result; diff --git a/test/test.nyan b/test/test.nyan index 2f5793b..c92e32a 100644 --- a/test/test.nyan +++ b/test/test.nyan @@ -28,6 +28,7 @@ Second(First): member *= 5.5 First.nice_member = False # nap : int + wat3 = None NestingBase(First):