Skip to content

Commit 36a625f

Browse files
committed
Rewrap after unwrap in apply_to_variables
1 parent 81c19e6 commit 36a625f

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
@@ -363,14 +363,15 @@ function Base.setproperty!(sys::AbstractSystem, prop::Symbol, val)
363363
end
364364
end
365365

366-
function apply_to_variables(f::F, ex) where {F}
367-
ex = value(ex)
366+
apply_to_variables(f::F, ex) where {F} = _apply_to_variables(f, ex)
367+
apply_to_variables(f::F, ex::Num) where {F} = wrap(_apply_to_variables(f, unwrap(ex)))
368+
function _apply_to_variables(f::F, ex) where {F}
368369
if isvariable(ex)
369370
return f(ex)
370371
end
371372
istree(ex) || return ex
372-
similarterm(ex, apply_to_variables(f, operation(ex)),
373-
map(Base.Fix1(apply_to_variables, f), arguments(ex)),
373+
similarterm(ex, _apply_to_variables(f, operation(ex)),
374+
map(Base.Fix1(_apply_to_variables, f), arguments(ex)),
374375
metadata = metadata(ex))
375376
end
376377

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)