@@ -212,17 +212,23 @@ 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) )
228
+ $ retval, $ (esc (:__varinfo__ )) = $ (DynamicPPL . _evaluate!!) (
229
+ $ (esc (expr)), $ (esc (:__varinfo__ )), $ (ctx)
225
230
)
231
+ $ retval
226
232
end
227
233
else
228
234
L, R = args_assign
@@ -235,9 +241,10 @@ function submodel(prefix_expr, expr, ctx=esc(:__context__))
235
241
)
236
242
end
237
243
quote
238
- $ ( esc (L)) , $ (esc (:__varinfo__ )) = $ (DynamicPPL. _evaluate!!)(
244
+ $ retval , $ (esc (:__varinfo__ )) = $ (DynamicPPL. _evaluate!!)(
239
245
$ (esc (R)), $ (esc (:__varinfo__ )), $ (ctx)
240
246
)
247
+ $ (esc (L)) = $ retval
241
248
end
242
249
end
243
250
end
0 commit comments