@@ -175,6 +175,9 @@ function unwrap_right_left_vns(
175175 return unwrap_right_left_vns(right, left, vns)
176176end
177177
178+ resolve_varnames(vn:: VarName , _) = vn
179+ resolve_varnames(vn:: VarName , dist:: NamedDist ) = dist. name
180+
178181# ################
179182# Main Compiler #
180183# ################
@@ -379,16 +382,19 @@ function generate_tilde(left, right)
379382
380383 # Otherwise it is determined by the model or its value,
381384 # if the LHS represents an observation
382- @gensym vn isassumption value
385+ @gensym vn isassumption value dist
383386
384387 # HACK: Usage of `drop_escape` is unfortunate. It's a consequence of the fact
385388 # that in DynamicPPL we the entire function body. Instead we should be
386389 # more selective with our escape. Until that's the case, we remove them all.
387390 return quote
388- $ vn = $ (AbstractPPL. drop_escape(varname(left)))
391+ $ dist = $ right
392+ $ vn = $ (DynamicPPL. resolve_varnames)(
393+ $ (AbstractPPL. drop_escape(varname(left))), $ dist
394+ )
389395 $ isassumption = $ (DynamicPPL. isassumption(left, vn))
390396 if $ isassumption
391- $ (generate_tilde_assume(left, right , vn))
397+ $ (generate_tilde_assume(left, dist , vn))
392398 else
393399 # If `vn` is not in `argnames`, we need to make sure that the variable is defined.
394400 if ! $ (DynamicPPL. inargnames)($ vn, __model__)
@@ -397,7 +403,7 @@ function generate_tilde(left, right)
397403
398404 $ value, __varinfo__ = $ (DynamicPPL. tilde_observe!!)(
399405 __context__,
400- $ (DynamicPPL. check_tilde_rhs)($ right ),
406+ $ (DynamicPPL. check_tilde_rhs)($ dist ),
401407 $ (maybe_view(left)),
402408 $ vn,
403409 __varinfo__,
@@ -442,7 +448,9 @@ function generate_dot_tilde(left, right)
442448 # if the LHS represents an observation
443449 @gensym vn isassumption value
444450 return quote
445- $ vn = $ (AbstractPPL. drop_escape(varname(left)))
451+ $ vn = $ (DynamicPPL. resolve_varnames)(
452+ $ (AbstractPPL. drop_escape(varname(left))), $ right
453+ )
446454 $ isassumption = $ (DynamicPPL. isassumption(left, vn))
447455 if $ isassumption
448456 $ (generate_dot_tilde_assume(left, right, vn))
0 commit comments