From 155bbc2f731d37e944be041f3dc3e51bb71fdb83 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Fri, 9 May 2025 15:02:08 +0530 Subject: [PATCH] refactor: add error message for wrapped variable in `collect_var!` --- src/utils.jl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/utils.jl b/src/utils.jl index d0fd3d40f9..90431a7749 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -606,6 +606,17 @@ end function collect_var!(unknowns, parameters, var, iv; depth = 0) isequal(var, iv) && return nothing + if Symbolics.iswrapped(var) + error(""" + Internal Error. Please open an issue with an MWE. + + Encountered a wrapped value in `collect_var!`. This function should only ever \ + receive unwrapped symbolic variables. This is likely a bug in the code generating \ + an expression passed to `collect_vars!` or `collect_scoped_vars!`. A common cause \ + is using `substitute` or `fast_substitute` with rules where the values are \ + wrapped symbolic variables. + """) + end check_scope_depth(getmetadata(var, SymScope, LocalScope()), depth) || return nothing var = setmetadata(var, SymScope, LocalScope()) if iscalledparameter(var)