Summary
ConstitutiveModel's add_scalar_input, add_tensor_input, add_parameter, and both add_output overloads do no name-collision checking. Duplicate names silently push duplicate entries into m_symbols / m_outputs, producing invalid C++ later:
add_parameter("E", 200e3) twice → two double const E formal parameters → C++ redefinition error.
add_output("sigma", expr1) then add_output("sigma", expr2) → two T_n & sigma_out parameters + two assignment statements → C++ error, plus the MOOSE backend declares the property twice → MOOSE runtime error.
The user gets a confusing downstream error instead of a clear recipe-time std::runtime_error("duplicate parameter 'E'").
Where
include/numsim_codegen/recipe.h:94-104 (add_scalar_input)
include/numsim_codegen/recipe.h:106-117 (add_tensor_input)
include/numsim_codegen/recipe.h:121-133 (add_parameter)
include/numsim_codegen/recipe.h:137-150 (both add_output overloads)
Fix
In every add_* method:
- Check
m_symbols for an existing entry with the same name (inputs/params share a namespace because they all become function parameters).
- For
add_output, also check m_outputs.
- Throw
std::runtime_error("duplicate <kind> '<name>'") on collision.
Pair with tests in tests/RecipeTest.cpp exercising each duplicate path. Worth also adding an identifier validator (reject C++ keywords, leading digits, names ending in _out) in the same pass — see the medium follow-up issue.
Refs
- REVIEW.md → CORR-A4 (High), CORR-24, CORR-25
- Severity: High
Summary
ConstitutiveModel'sadd_scalar_input,add_tensor_input,add_parameter, and bothadd_outputoverloads do no name-collision checking. Duplicate names silently push duplicate entries intom_symbols/m_outputs, producing invalid C++ later:add_parameter("E", 200e3)twice → twodouble const Eformal parameters → C++ redefinition error.add_output("sigma", expr1)thenadd_output("sigma", expr2)→ twoT_n & sigma_outparameters + two assignment statements → C++ error, plus the MOOSE backend declares the property twice → MOOSE runtime error.The user gets a confusing downstream error instead of a clear recipe-time
std::runtime_error("duplicate parameter 'E'").Where
include/numsim_codegen/recipe.h:94-104(add_scalar_input)include/numsim_codegen/recipe.h:106-117(add_tensor_input)include/numsim_codegen/recipe.h:121-133(add_parameter)include/numsim_codegen/recipe.h:137-150(bothadd_outputoverloads)Fix
In every
add_*method:m_symbolsfor an existing entry with the samename(inputs/params share a namespace because they all become function parameters).add_output, also checkm_outputs.std::runtime_error("duplicate <kind> '<name>'")on collision.Pair with tests in
tests/RecipeTest.cppexercising each duplicate path. Worth also adding an identifier validator (reject C++ keywords, leading digits, names ending in_out) in the same pass — see the medium follow-up issue.Refs