Skip to content

Commit

Permalink
Add causality check in add_variable_value()
Browse files Browse the repository at this point in the history
This is a small compensation for the check that was removed to fix #742.
Modifying variables with `constant` variability is never allowed.
  • Loading branch information
kyllingstad committed Oct 17, 2023
1 parent d880ac8 commit 5c047cb
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/cosim/system_structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5c047cb

Please sign in to comment.