Skip to content

Commit

Permalink
Check for duplicate names during model parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
contradict committed Aug 7, 2024
1 parent efc835f commit eff05fb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/systems/model_parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,20 @@ function generate_var(a, varclass;
var
end

singular(sym) = last(string(sym)) == 's' ? Symbol(string(sym)[1:(end - 1)]) : sym

function check_name_uniqueness(dict, a, newvarclass)
for varclass in [:variables, :parameters, :structural_parameters, :constants]
if haskey(dict, varclass) && a in keys(dict[varclass])
error("Cannot create a $(singular(newvarclass)) `$(a)` because there is already a $(singular(varclass)) with that name")
end
end
end

function generate_var!(dict, a, varclass;
indices::Union{Vector{UnitRange{Int}}, Nothing} = nothing,
type = Real)
check_name_uniqueness(dict, a, varclass)
vd = get!(dict, varclass) do
Dict{Symbol, Dict{Symbol, Any}}()
end
Expand All @@ -302,6 +313,7 @@ function generate_var!(dict, a, b, varclass, mod;
iv
end
@assert isequal(iv, prev_iv) "Multiple independent variables are used in the model"
check_name_uniqueness(dict, a, varclass)
vd = get!(dict, varclass) do
Dict{Symbol, Dict{Symbol, Any}}()
end
Expand Down

0 comments on commit eff05fb

Please sign in to comment.