Skip to content

Recipe builders silently accept duplicate add_* calls #9

Description

@petlenz

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:

  1. Check m_symbols for an existing entry with the same name (inputs/params share a namespace because they all become function parameters).
  2. For add_output, also check m_outputs.
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions