@@ -305,10 +305,11 @@ function make_reaction_system(ex::Expr, name)
305305 union (syms_declared, sps_inferred), tiv; requiredec)
306306 ps_inferred = setdiff (ps_pre_inferred, vs_inferred, diffs_inferred)
307307 syms_inferred = union (sps_inferred, ps_inferred, vs_inferred, diffs_inferred)
308+ all_syms = union (syms_declared, syms_inferred)
308309
309310 # Read options not related to the declaration or inference of symbols.
310311 obsexpr, obs_eqs, obs_syms = read_observed_options (options, ivs,
311- union (sps_declared, vs_declared), union (syms_declared, syms_inferred) ; requiredec)
312+ union (sps_declared, vs_declared), all_syms ; requiredec)
312313 continuous_events_expr = read_events_option (options, :continuous_events )
313314 discrete_events_expr = read_events_option (options, :discrete_events )
314315 default_reaction_metadata = read_default_noise_scaling_option (options)
@@ -322,7 +323,7 @@ function make_reaction_system(ex::Expr, name)
322323 spsexpr, spsvar = scalarize_macro (spsexpr_init, " specs" )
323324 vsexpr, vsvar = scalarize_macro (vsexpr_init, " vars" )
324325 cmpsexpr, cmpsvar = scalarize_macro (cmpexpr_init, " comps" )
325- rxsexprs = get_rxexprs (reactions, equations, union (diffs_declared, diffs_inferred) )
326+ rxsexprs = get_rxexprs (reactions, equations, all_syms )
326327
327328 # Assemblies the full expression that declares all required symbolic variables, and
328329 # then the output `ReactionSystem`.
@@ -565,10 +566,10 @@ end
565566
566567# From the system reactions (as `DSLReaction`s) and equations (as expressions),
567568# creates the expressions that evaluates to the reaction (+ equations) vector.
568- function get_rxexprs (reactions, equations, diffsyms )
569+ function get_rxexprs (reactions, equations, all_syms )
569570 rxsexprs = :(Catalyst. CatalystEqType[])
570571 foreach (rx -> push! (rxsexprs. args, get_rxexpr (rx)), reactions)
571- foreach (eq -> push! (rxsexprs. args, escape_equation! (eq, diffsyms )), equations)
572+ foreach (eq -> push! (rxsexprs. args, escape_equation! (eq, all_syms )), equations)
572573 return rxsexprs
573574end
574575
@@ -598,10 +599,12 @@ function get_rxexpr(rx::DSLReaction)
598599end
599600
600601# Recursively escape functions within equations of an equation written using user-defined functions.
601- # Does not expand special function calls like "hill(...)" and differential operators.
602- function escape_equation! (eqexpr:: Expr , diffsyms)
603- eqexpr. args[2 ] = recursive_escape_functions! (eqexpr. args[2 ], diffsyms)
604- eqexpr. args[3 ] = recursive_escape_functions! (eqexpr. args[3 ], diffsyms)
602+ # Does not escape special function calls like "hill(...)" and differential operators. Does
603+ # also not escape stuff corresponding to e.g. species or parameters (required for good error
604+ # for when e.g. a species is used as a differential, or for time delays in the future).
605+ function escape_equation! (eqexpr:: Expr , all_syms)
606+ eqexpr. args[2 ] = recursive_escape_functions! (eqexpr. args[2 ], all_syms)
607+ eqexpr. args[3 ] = recursive_escape_functions! (eqexpr. args[3 ], all_syms)
605608 eqexpr
606609end
607610
@@ -934,9 +937,6 @@ function make_reaction(ex::Expr)
934937 reaction = get_reaction (ex)
935938 species, parameters = extract_sps_and_ps ([reaction], [])
936939
937- # Checks for input errors.
938- forbidden_symbol_check (union (species, parameters))
939-
940940 # Creates expressions corresponding to code for declaring the parameters, species, and reaction.
941941 spexprs = get_usexpr (species, Dict {Symbol, Expr} ())
942942 pexprs = get_psexpr (parameters, Dict {Symbol, Expr} ())
@@ -964,11 +964,11 @@ end
964964
965965# Recursively traverses an expression and escapes all the user-defined functions.
966966# Special function calls like "hill(...)" are not expanded.
967- function recursive_escape_functions! (expr:: ExprValues , diffsyms = [])
967+ function recursive_escape_functions! (expr:: ExprValues , syms_skip = [])
968968 (typeof (expr) != Expr) && (return expr)
969- foreach (i -> expr. args[i] = recursive_escape_functions! (expr. args[i], diffsyms ),
969+ foreach (i -> expr. args[i] = recursive_escape_functions! (expr. args[i], syms_skip ),
970970 1 : length (expr. args))
971- if (expr. head == :call ) && ! isdefined (Catalyst, expr. args[1 ]) && expr. args[1 ] ∉ diffsyms
971+ if (expr. head == :call ) && ! isdefined (Catalyst, expr. args[1 ]) && expr. args[1 ] ∉ syms_skip
972972 expr. args[1 ] = esc (expr. args[1 ])
973973 end
974974 expr
0 commit comments