From 5c047cb111815ed9f72091764e04b48f531ddacf Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Tue, 17 Oct 2023 20:46:58 +0200 Subject: [PATCH] Add causality check in add_variable_value() This is a small compensation for the check that was removed to fix #742. Modifying variables with `constant` variability is never allowed. --- src/cosim/system_structure.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cosim/system_structure.cpp b/src/cosim/system_structure.cpp index 814451824..4e285c602 100644 --- a/src/cosim/system_structure.cpp +++ b/src/cosim/system_structure.cpp @@ -391,6 +391,11 @@ void add_variable_value( scalar_value value) { const auto& varDescription = systemStructure.get_variable_description(variable); + if (varDescription.variability == variable_variability::constant) { + std::ostringstream msg; + msg << "Cannot modify value of constant variable '" << variable << "'"; + throw error(make_error_code(errc::invalid_system_structure), msg.str()); + } if (std::string e; !is_valid_variable_value(varDescription, value, &e)) { std::ostringstream msg; msg << "Invalid value for variable '" << variable << "': " << e;