Skip to content

Commit 650c69a

Browse files
authored
Merge branch 'master' into tor/tilde-simplification
2 parents 300f4b6 + c95ccfa commit 650c69a

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/compiler.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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

test/compiler.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff 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
451464
end

0 commit comments

Comments
 (0)