@@ -239,50 +239,51 @@ function DynamicPPL.setchildcontext(context::DebugContext, child)
239239end
240240
241241function record_varname! (context:: DebugContext , varname:: VarName , dist)
242- if haskey (context. varnames_seen, varname)
242+ prefixed_varname = prefix (context, varname)
243+ if haskey (context. varnames_seen, prefixed_varname)
243244 if context. error_on_failure
244- error (" varname $varname used multiple times in model" )
245+ error (" varname $prefixed_varname used multiple times in model" )
245246 else
246- @warn " varname $varname used multiple times in model"
247+ @warn " varname $prefixed_varname used multiple times in model"
247248 end
248- context. varnames_seen[varname ] += 1
249+ context. varnames_seen[prefixed_varname ] += 1
249250 else
250251 # We need to check:
251252 # 1. Does this `varname` subsume any of the other keys.
252253 # 2. Does any of the other keys subsume `varname`.
253254 vns = collect (keys (context. varnames_seen))
254255 # Is `varname` subsumed by any of the other keys?
255- idx_parent = findfirst (Base. Fix2 (subsumes, varname ), vns)
256+ idx_parent = findfirst (Base. Fix2 (subsumes, prefixed_varname ), vns)
256257 if idx_parent != = nothing
257258 varname_parent = vns[idx_parent]
258259 if context. error_on_failure
259260 error (
260- " varname $(varname_parent) used multiple times in model (subsumes $varname )" ,
261+ " varname $(varname_parent) used multiple times in model (subsumes $prefixed_varname )" ,
261262 )
262263 else
263- @warn " varname $(varname_parent) used multiple times in model (subsumes $varname )"
264+ @warn " varname $(varname_parent) used multiple times in model (subsumes $prefixed_varname )"
264265 end
265266 # Update count of parent.
266267 context. varnames_seen[varname_parent] += 1
267268 else
268269 # Does `varname` subsume any of the other keys?
269- idx_child = findfirst (Base. Fix1 (subsumes, varname ), vns)
270+ idx_child = findfirst (Base. Fix1 (subsumes, prefixed_varname ), vns)
270271 if idx_child != = nothing
271272 varname_child = vns[idx_child]
272273 if context. error_on_failure
273274 error (
274- " varname $(varname_child) used multiple times in model (subsumed by $varname )" ,
275+ " varname $(varname_child) used multiple times in model (subsumed by $prefixed_varname )" ,
275276 )
276277 else
277- @warn " varname $(varname_child) used multiple times in model (subsumed by $varname )"
278+ @warn " varname $(varname_child) used multiple times in model (subsumed by $prefixed_varname )"
278279 end
279280
280281 # Update count of child.
281282 context. varnames_seen[varname_child] += 1
282283 end
283284 end
284285
285- context. varnames_seen[varname ] = 1
286+ context. varnames_seen[prefixed_varname ] = 1
286287 end
287288end
288289
0 commit comments