Skip to content

Commit

Permalink
Merge pull request #431 from luke-kiernan/set_name_no_op
Browse files Browse the repository at this point in the history
set_name to own name is a no-op, not an error
  • Loading branch information
jd-lara authored Feb 1, 2025
2 parents 17ccd3b + 642a052 commit 6740245
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ function set_name!(
) where {T <: InfrastructureSystemsComponent}
throw_if_not_attached(components, component)
if haskey(components.data[T], name)
if components.data[T][name] === component
return
end
throw(ArgumentError("A component of type $T and name = $name is already stored"))
end

Expand Down
1 change: 1 addition & 0 deletions test/test_system_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ end
name = "component1"
component = IS.TestComponent(name, 5)
IS.add_component!(data, component)
@test IS.set_name!(data, component, name) isa Any # shouldn't throw.

new_name = "component1-new"
IS.set_name!(data, component, new_name)
Expand Down

0 comments on commit 6740245

Please sign in to comment.