Skip to content

Commit 9431df0

Browse files
committed
Fix models with type annotations (#183) (#184)
Fixes #183.
1 parent 8c9004e commit 9431df0

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DynamicPPL"
22
uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8"
3-
version = "0.9.6"
3+
version = "0.9.7"
44

55
[deps]
66
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"

src/compiler.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function model(expr, warn)
7070

7171
# Generate main body
7272
modelinfo[:body] = generate_mainbody(
73-
modelinfo[:modeldef][:body], modelinfo[:allargs_exprs], warn
73+
modelinfo[:modeldef][:body], modelinfo[:allargs_syms], warn
7474
)
7575

7676
return build_output(modelinfo)
@@ -117,7 +117,7 @@ function build_model_info(input_expr)
117117
allargs_exprs = first.(allargs_exprs_defaults)
118118

119119
# Extract the names of the arguments.
120-
allargs_syms = map(allargs_exprs_defaults) do (arg, _)
120+
allargs_syms = map(allargs_exprs) do arg
121121
MacroTools.@match arg begin
122122
(::Type{T_}) | (name_::Type{T_}) => T
123123
name_::T_ => name

test/compiler.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,4 +635,15 @@ end
635635
m = demo(0.)
636636
@test m() isa Float64
637637
end
638+
@testset "type annotations" begin
639+
@model function demo_without(x)
640+
x ~ Normal()
641+
end
642+
@test isempty(VarInfo(demo_without(0.0)))
643+
644+
@model function demo_with(x::Real)
645+
x ~ Normal()
646+
end
647+
@test isempty(VarInfo(demo_with(0.0)))
648+
end
638649
end

0 commit comments

Comments
 (0)