Skip to content

Commit 1d14c9b

Browse files
authored
Merge pull request #2079 from SciML/myb/wrap
Rewrap after unwrap in `apply_to_variables`
2 parents 62d8b2a + 36a625f commit 1d14c9b

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/systems/abstractsystem.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,15 @@ function Base.setproperty!(sys::AbstractSystem, prop::Symbol, val)
371371
end
372372
end
373373

374-
function apply_to_variables(f::F, ex) where {F}
375-
ex = value(ex)
374+
apply_to_variables(f::F, ex) where {F} = _apply_to_variables(f, ex)
375+
apply_to_variables(f::F, ex::Num) where {F} = wrap(_apply_to_variables(f, unwrap(ex)))
376+
function _apply_to_variables(f::F, ex) where {F}
376377
if isvariable(ex)
377378
return f(ex)
378379
end
379380
istree(ex) || return ex
380-
similarterm(ex, apply_to_variables(f, operation(ex)),
381-
map(Base.Fix1(apply_to_variables, f), arguments(ex)),
381+
similarterm(ex, _apply_to_variables(f, operation(ex)),
382+
map(Base.Fix1(_apply_to_variables, f), arguments(ex)),
382383
metadata = metadata(ex))
383384
end
384385

test/variable_scope.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ using Test
99
b = ParentScope(b)
1010
c = ParentScope(ParentScope(c))
1111
d = GlobalScope(d)
12+
@test all(x -> x isa Num, [b, c, d])
1213

1314
# ensure it works on Term too
1415
LocalScope(e.val)

0 commit comments

Comments
 (0)