Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DynamicPPL"
uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8"
version = "0.11.3"
version = "0.11.4"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
5 changes: 5 additions & 0 deletions src/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ function build_model_info(input_expr)
# Break up the model definition and extract its name, arguments, and function body
modeldef = MacroTools.splitdef(input_expr)

# Check that the function has a name
# https://github.com/TuringLang/DynamicPPL.jl/issues/260
haskey(modeldef, :name) ||
throw(ArgumentError("anonymous functions without name are not supported"))

# Print a warning if function body of the model is empty
warn_empty(modeldef[:body])

Expand Down
17 changes: 15 additions & 2 deletions test/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,25 @@ end
return [10.0, 10.0] ~ MvNormal(m, 0.5 * ones(2))
end) isa Function

@model function array_literal_model()
@model function array_literal_model2()
# `assume` and literal `observe`
m ~ MvNormal(2, 1.0)
return [10.0, 10.0] ~ MvNormal(m, 0.5 * ones(2))
end

@test array_literal_model()() == [10.0, 10.0]
@test array_literal_model2()() == [10.0, 10.0]
end

# https://github.com/TuringLang/DynamicPPL.jl/issues/260
@testset "anonymous function" begin
error = ArgumentError("anonymous functions without name are not supported")
@test_throws LoadError(@__FILE__, (@__LINE__) + 1, error) @macroexpand begin
@model function (x)
return x ~ Normal()
end
end
@test_throws LoadError(@__FILE__, (@__LINE__) + 1, error) @macroexpand begin
model = @model(x -> (x ~ Normal()))
end
end
end