@@ -275,9 +275,13 @@ function parse_variable_def!(dict, mod, arg, varclass, kwargs, where_types;
275275            varval =  (@isdefined  default_val) ?  default_val : 
276276                     unit_handled_variable_value (meta, varname)
277277            if  varclass ==  :parameters 
278+                 Meta. isexpr (a, :call ) &&  assert_unique_independent_var (dict, a. args[end ])
278279                var =  :($ varname =  $ first (@parameters  ($ a[$ (indices... )]:: $type  =  $ varval),
279280                $ meta_val))
280281            else 
282+                 Meta. isexpr (a, :call ) || 
283+                     throw (" $a  is not a variable of the independent variable"  )
284+                 assert_unique_independent_var (dict, a. args[end ])
281285                var =  :($ varname =  $ first (@variables  ($ a[$ (indices)]:: $type  =  $ varval),
282286                $ meta_val))
283287            end 
@@ -295,10 +299,15 @@ function parse_variable_def!(dict, mod, arg, varclass, kwargs, where_types;
295299                val, def_n_meta =  (def_n_meta. args[1 ], def_n_meta. args[2 : end ])
296300                push! (kwargs, Expr (:kw , varname, nothing ))
297301                if  varclass ==  :parameters 
302+                     Meta. isexpr (a, :call ) && 
303+                         assert_unique_independent_var (dict, a. args[end ])
298304                    var =  :($ varname =  $ varname ===  nothing  ?  $ val :  $ varname;
299305                    $ varname =  $ first (@parameters  ($ a[$ (indices... )]:: $type  =  $ varval),
300306                    $ (def_n_meta... )))
301307                else 
308+                     Meta. isexpr (a, :call ) || 
309+                         throw (" $a  is not a variable of the independent variable"  )
310+                     assert_unique_independent_var (dict, a. args[end ])
302311                    var =  :($ varname =  $ varname ===  nothing  ?  $ val :  $ varname;
303312                    $ varname =  $ first (@variables  $ a[$ (indices... )]:: $type  =  (
304313                        $ varval),
@@ -307,9 +316,14 @@ function parse_variable_def!(dict, mod, arg, varclass, kwargs, where_types;
307316            else 
308317                push! (kwargs, Expr (:kw , varname, nothing ))
309318                if  varclass ==  :parameters 
319+                     Meta. isexpr (a, :call ) && 
320+                         assert_unique_independent_var (dict, a. args[end ])
310321                    var =  :($ varname =  $ varname ===  nothing  ?  $ def_n_meta :  $ varname;
311322                    $ varname =  $ first (@parameters  $ a[$ (indices... )]:: $type  =  $ varname))
312323                else 
324+                     Meta. isexpr (a, :call ) || 
325+                         throw (" $a  is not a variable of the independent variable"  )
326+                     assert_unique_independent_var (dict, a. args[end ])
313327                    var =  :($ varname =  $ varname ===  nothing  ?  $ def_n_meta :  $ varname;
314328                    $ varname =  $ first (@variables  $ a[$ (indices... )]:: $type  =  $ varname))
315329                end 
@@ -325,8 +339,12 @@ function parse_variable_def!(dict, mod, arg, varclass, kwargs, where_types;
325339            varname =  a isa  Expr &&  a. head ==  :call  ?  a. args[1 ] :  a
326340            push! (kwargs, Expr (:kw , varname, nothing ))
327341            if  varclass ==  :parameters 
342+                 Meta. isexpr (a, :call ) &&  assert_unique_independent_var (dict, a. args[end ])
328343                var =  :($ varname =  $ first (@parameters  $ a[$ (indices... )]:: $type  =  $ varname))
329344            elseif  varclass ==  :variables 
345+                 Meta. isexpr (a, :call ) || 
346+                     throw (" $a  is not a variable of the independent variable"  )
347+                 assert_unique_independent_var (dict, a. args[end ])
330348                var =  :($ varname =  $ first (@variables  $ a[$ (indices... )]:: $type  =  $ varname))
331349            else 
332350                throw (" Symbolic array with arbitrary length is not handled for $varclass .
@@ -405,14 +423,22 @@ function generate_var!(dict, a, varclass;
405423    generate_var (a, varclass; indices, type)
406424end 
407425
426+ function  assert_unique_independent_var (dict, iv:: Num )
427+     assert_unique_independent_var (dict, nameof (iv))
428+ end 
429+ function  assert_unique_independent_var (dict, iv)
430+     prev_iv =  get! (dict, :independent_variable ) do 
431+         iv
432+     end 
433+     prev_iv isa  Num &&  (prev_iv =  nameof (prev_iv))
434+     @assert  isequal (iv, prev_iv) " Multiple independent variables are used in the model $(typeof (iv))  $(typeof (prev_iv)) " 
435+ end 
436+ 
408437function  generate_var! (dict, a, b, varclass, mod;
409438        indices:: Union{Vector{UnitRange{Int}}, Nothing}  =  nothing ,
410439        type =  Real)
411440    iv =  b ==  :t  ?  get_t (mod, b) :  generate_var (b, :independent_variables )
412-     prev_iv =  get! (dict, :independent_variable ) do 
413-         iv
414-     end 
415-     @assert  isequal (iv, prev_iv) " Multiple independent variables are used in the model" 
441+     assert_unique_independent_var (dict, iv)
416442    check_name_uniqueness (dict, a, varclass)
417443    vd =  get! (dict, varclass) do 
418444        Dict {Symbol, Dict{Symbol, Any}} ()
0 commit comments