File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,11 @@ function build_model_info(input_expr)
152152 # Break up the model definition and extract its name, arguments, and function body
153153 modeldef = MacroTools. splitdef (input_expr)
154154
155+ # Check that the function has a name
156+ # https://github.com/TuringLang/DynamicPPL.jl/issues/260
157+ haskey (modeldef, :name ) ||
158+ throw (ArgumentError (" anonymous functions without name are not supported" ))
159+
155160 # Print a warning if function body of the model is empty
156161 warn_empty (modeldef[:body ])
157162
Original file line number Diff line number Diff line change @@ -440,12 +440,25 @@ end
440440 return [10.0 , 10.0 ] ~ MvNormal (m, 0.5 * ones (2 ))
441441 end ) isa Function
442442
443- @model function array_literal_model ()
443+ @model function array_literal_model2 ()
444444 # `assume` and literal `observe`
445445 m ~ MvNormal (2 , 1.0 )
446446 return [10.0 , 10.0 ] ~ MvNormal (m, 0.5 * ones (2 ))
447447 end
448448
449- @test array_literal_model ()() == [10.0 , 10.0 ]
449+ @test array_literal_model2 ()() == [10.0 , 10.0 ]
450+ end
451+
452+ # https://github.com/TuringLang/DynamicPPL.jl/issues/260
453+ @testset " anonymous function" begin
454+ error = ArgumentError (" anonymous functions without name are not supported" )
455+ @test_throws LoadError (@__FILE__ , (@__LINE__ ) + 1 , error) @macroexpand begin
456+ @model function (x)
457+ return x ~ Normal ()
458+ end
459+ end
460+ @test_throws LoadError (@__FILE__ , (@__LINE__ ) + 1 , error) @macroexpand begin
461+ model = @model (x -> (x ~ Normal ()))
462+ end
450463 end
451464end
You can’t perform that action at this time.
0 commit comments