Skip to content

Commit 67622b9

Browse files
committed
Add tests for old .~ syntax
1 parent af8b017 commit 67622b9

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/compiler.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,33 @@ module Issue537 end
288288
x = vdemo()()
289289
@test all((isassigned(x, i) for i in eachindex(x)))
290290
end
291+
292+
# A couple of uses of .~ that are no longer valid as of v0.35.
293+
@testset "old .~ syntax" begin
294+
@model function multivariate_dot_tilde()
295+
x = Vector{Float64}(undef, 2)
296+
x .~ MvNormal(zeros(2), I)
297+
return x
298+
end
299+
expected_error = ArgumentError(
300+
"the right-hand side of a `.~` must be a `UnivariateDistribution`"
301+
)
302+
@test_throws expected_error (multivariate_dot_tilde()(); true)
303+
304+
@model function vector_dot_tilde()
305+
x = Vector{Float64}(undef, 2)
306+
x .~ [Normal(), Normal()]
307+
return x
308+
end
309+
expected_error = ArgumentError("""
310+
As of v0.35, DynamicPPL does not allow arrays of distributions in `.~`. \
311+
Please use `product_distribution` instead, or write a loop if necessary. \
312+
See https://github.com/TuringLang/DynamicPPL.jl/releases/tag/v0.35.0 for more \
313+
details.\
314+
""")
315+
@test_throws expected_error (vector_dot_tilde()(); true)
316+
end
317+
291318
@testset "nested model" begin
292319
function makemodel(p)
293320
@model function testmodel(x)

0 commit comments

Comments
 (0)