diff --git a/src/structural_transformation/symbolics_tearing.jl b/src/structural_transformation/symbolics_tearing.jl index 8f87f6d31f..39b959c5a6 100644 --- a/src/structural_transformation/symbolics_tearing.jl +++ b/src/structural_transformation/symbolics_tearing.jl @@ -972,7 +972,10 @@ function update_simplified_system!( # Algebraic variables are shifted forward by one, so we backshift them. unknowns = map(enumerate(unknowns)) do (i, var) if iscall(var) && operation(var) isa Shift && operation(var).steps == 1 - backshift_expr(var, iv) + # We might have shifted a variable with io metadata. That is irrelevant now + # because we handled io variables earlier in `_mtkcompile!` so just ignore + # it here. + setio(backshift_expr(var, iv), false, false) else var end diff --git a/test/symbolic_events.jl b/test/symbolic_events.jl index 886813a37f..54ac59bdf4 100644 --- a/test/symbolic_events.jl +++ b/test/symbolic_events.jl @@ -1410,3 +1410,12 @@ end sol = solve(prob, FBDF()) @test SciMLBase.successful_retcode(sol) end + +@testset "Algebraic equation with input variable in symbolic affect" begin + # Specifically happens when the variable marked as an input is an algebraic variable + # in the affect system. + @variables x(t) [input = true] y(t) + dev = ModelingToolkit.SymbolicDiscreteCallback(1.0, [y ~ Pre(y) + 1]) + @named sys = System([D(y) ~ 2x + 1, x^2 ~ 2y^3], t; discrete_events = [dev]) + sys = @test_nowarn mtkcompile(sys) +end