Skip to content

Commit 7161599

Browse files
committed
Fix a bug in nested decondition_context
1 parent 90254fa commit 7161599

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

src/contexts.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,9 @@ function decondition_context(context::ConditionContext, sym, syms...)
447447
# No more values left, can unwrap
448448
decondition_context(childcontext(context), syms...)
449449
else
450-
ConditionContext(new_values, decondition_context(childcontext(context), syms...))
450+
ConditionContext(
451+
new_values, decondition_context(childcontext(context), sym, syms...)
452+
)
451453
end
452454
end
453455
function decondition_context(context::NamedConditionContext, vn::VarName{sym}) where {sym}

test/contexts.jl

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ end
133133
@test hasconditioned_nested(context, vn_child)
134134
# Value should be the same as extracted above.
135135
@test getconditioned_nested(context, vn_child) ===
136-
getoptic(vn_child)(val)
136+
getoptic(vn_child)(val)
137137
end
138138
end
139139
end
@@ -257,7 +257,25 @@ end
257257
@test dctx.values == Dict(@varname(x) => 1)
258258
# Decondition all variables manually
259259
@test decondition_context(ctx, @varname(x), @varname(y), @varname(z)) isa
260-
DefaultContext
260+
DefaultContext
261+
end
262+
263+
@testset "Nesting" begin
264+
ctx = ConditionContext(
265+
(x=1, y=2),
266+
ConditionContext(Dict(@varname(a) => 3, @varname(b) => 4))
267+
)
268+
# Decondition an outer variable
269+
dctx = decondition_context(ctx, :x)
270+
@test dctx.values == (y=2,)
271+
@test childcontext(dctx).values == Dict(@varname(a) => 3, @varname(b) => 4)
272+
# Decondition an inner variable
273+
dctx = decondition_context(ctx, @varname(a))
274+
@test dctx.values == (x=1, y=2)
275+
@test childcontext(dctx).values == Dict(@varname(b) => 4)
276+
# Try deconditioning everything
277+
dctx = decondition_context(ctx)
278+
@test dctx isa DefaultContext
261279
end
262280
end
263281
end

0 commit comments

Comments
 (0)