Skip to content

Commit 2c3244e

Browse files
committed
Replace end in model macro (fix #61)
1 parent 1ebadd1 commit 2c3244e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/compiler.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ end
7070
To generate a `Model`, call `model_generator(x_value)`.
7171
"""
7272
macro model(input_expr)
73-
build_model_info(input_expr) |> replace_tilde! |> replace_vi! |>
73+
Base.replace_ref_end!(input_expr) |> build_model_info |> replace_tilde! |> replace_vi! |>
7474
replace_logpdf! |> replace_sampler! |> build_output
7575
end
7676

test/compiler.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ priors = 0 # See "new grammar" test.
212212
model(varinfo)
213213
@test getlogp(varinfo) == lp
214214
@test varinfo === _varinfo
215+
216+
# test DPPL#61
217+
@model testmodel(z) = begin
218+
m ~ Normal()
219+
z[1:end] ~ MvNormal(fill(m, length(z)), 1.0)
220+
return m
221+
end
222+
model = testmodel(rand(10))
223+
@test all(z -> isapprox(z, 0; atol = 0.2), mean(model() for _ in 1:1000))
215224
end
216225
@testset "nested model" begin
217226
function makemodel(p)

0 commit comments

Comments
 (0)