@@ -212,17 +212,21 @@ function submodel(prefix_expr, expr, ctx=esc(:__context__))
212
212
if prefix_left != = :prefix
213
213
error (" $(prefix_left) is not a valid kwarg" )
214
214
end
215
+
216
+ # The user expects `@submodel ...` to return the
217
+ # return-value of the `...`, hence we need to capture
218
+ # the return-value and handle it correctly.
219
+ @gensym retval
220
+
215
221
# `prefix=false` => don't prefix, i.e. do nothing to `ctx`.
216
222
# `prefix=true` => automatically determine prefix.
217
223
# `prefix=...` => use it.
218
224
args_assign = getargs_assignment (expr)
219
225
return if args_assign === nothing
220
226
ctx = prefix_submodel_context (prefix, ctx)
221
- # In this case we only want to get the `__varinfo__`.
222
227
quote
223
- $ (esc (:__varinfo__ )) = last (
224
- $ (DynamicPPL. _evaluate!!)($ (esc (expr)), $ (esc (:__varinfo__ )), $ (ctx))
225
- )
228
+ $ retval, $ (esc (:__varinfo__ )) = $ (DynamicPPL. _evaluate!!)($ (esc (expr)), $ (esc (:__varinfo__ )), $ (ctx))
229
+ $ retval
226
230
end
227
231
else
228
232
L, R = args_assign
@@ -235,9 +239,10 @@ function submodel(prefix_expr, expr, ctx=esc(:__context__))
235
239
)
236
240
end
237
241
quote
238
- $ ( esc (L)) , $ (esc (:__varinfo__ )) = $ (DynamicPPL. _evaluate!!)(
242
+ $ retval , $ (esc (:__varinfo__ )) = $ (DynamicPPL. _evaluate!!)(
239
243
$ (esc (R)), $ (esc (:__varinfo__ )), $ (ctx)
240
244
)
245
+ esc (L) = $ retval
241
246
end
242
247
end
243
248
end
0 commit comments