File tree 3 files changed +21
-3
lines changed
3 files changed +21
-3
lines changed Original file line number Diff line number Diff line change 1
1
name = " DynamicPPL"
2
2
uuid = " 366bfd00-2699-11ea-058f-f148b4cae6d8"
3
- version = " 0.11.3 "
3
+ version = " 0.11.4 "
4
4
5
5
[deps ]
6
6
AbstractMCMC = " 80f14c24-f653-4e6a-9b94-39d6b0f70001"
Original file line number Diff line number Diff line change @@ -109,6 +109,11 @@ function build_model_info(input_expr)
109
109
# Break up the model definition and extract its name, arguments, and function body
110
110
modeldef = MacroTools. splitdef (input_expr)
111
111
112
+ # Check that the function has a name
113
+ # https://github.com/TuringLang/DynamicPPL.jl/issues/260
114
+ haskey (modeldef, :name ) ||
115
+ throw (ArgumentError (" anonymous functions without name are not supported" ))
116
+
112
117
# Print a warning if function body of the model is empty
113
118
warn_empty (modeldef[:body ])
114
119
Original file line number Diff line number Diff line change @@ -441,12 +441,25 @@ end
441
441
return [10.0 , 10.0 ] ~ MvNormal (m, 0.5 * ones (2 ))
442
442
end ) isa Function
443
443
444
- @model function array_literal_model ()
444
+ @model function array_literal_model2 ()
445
445
# `assume` and literal `observe`
446
446
m ~ MvNormal (2 , 1.0 )
447
447
return [10.0 , 10.0 ] ~ MvNormal (m, 0.5 * ones (2 ))
448
448
end
449
449
450
- @test array_literal_model ()() == [10.0 , 10.0 ]
450
+ @test array_literal_model2 ()() == [10.0 , 10.0 ]
451
+ end
452
+
453
+ # https://github.com/TuringLang/DynamicPPL.jl/issues/260
454
+ @testset " anonymous function" begin
455
+ error = ArgumentError (" anonymous functions without name are not supported" )
456
+ @test_throws LoadError (@__FILE__ , (@__LINE__ ) + 1 , error) @macroexpand begin
457
+ @model function (x)
458
+ return x ~ Normal ()
459
+ end
460
+ end
461
+ @test_throws LoadError (@__FILE__ , (@__LINE__ ) + 1 , error) @macroexpand begin
462
+ model = @model (x -> (x ~ Normal ()))
463
+ end
451
464
end
452
465
end
You can’t perform that action at this time.
0 commit comments