@@ -282,9 +282,20 @@ function generate_var(a, varclass;
282
282
var
283
283
end
284
284
285
+ singular (sym) = last (string (sym)) == ' s' ? Symbol (string (sym)[1 : (end - 1 )]) : sym
286
+
287
+ function check_name_uniqueness (dict, a, newvarclass)
288
+ for varclass in [:variables , :parameters , :structural_parameters , :constants ]
289
+ if haskey (dict, varclass) && a in keys (dict[varclass])
290
+ error (" Cannot create a $(singular (newvarclass)) `$(a) ` because there is already a $(singular (varclass)) with that name" )
291
+ end
292
+ end
293
+ end
294
+
285
295
function generate_var! (dict, a, varclass;
286
296
indices:: Union{Vector{UnitRange{Int}}, Nothing} = nothing ,
287
297
type = Real)
298
+ check_name_uniqueness (dict, a, varclass)
288
299
vd = get! (dict, varclass) do
289
300
Dict {Symbol, Dict{Symbol, Any}} ()
290
301
end
@@ -302,6 +313,7 @@ function generate_var!(dict, a, b, varclass, mod;
302
313
iv
303
314
end
304
315
@assert isequal (iv, prev_iv) " Multiple independent variables are used in the model"
316
+ check_name_uniqueness (dict, a, varclass)
305
317
vd = get! (dict, varclass) do
306
318
Dict {Symbol, Dict{Symbol, Any}} ()
307
319
end
0 commit comments