You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently on master:
``` julia
julia> using DynamicPPL, Distributions, LinearAlgebra
julia> @model test_defaults(x, n=length(x)) = x ~ MvNormal(zeros(n), I)
test_defaults (generic function with 3 methods)
julia> test_defaults(missing, 2)()
ERROR: MethodError: no method matching length(::Missing)
...
```
On this branch:
``` julia
julia> using DynamicPPL, Distributions, LinearAlgebra
julia> @model test_defaults(x, n=length(x)) = x ~ MvNormal(zeros(n), I)
test_defaults (generic function with 3 methods)
julia> test_defaults(missing, 2)()
2-element Vector{Float64}:
0.3028550279042859
0.6130034982853375
```
On master, this is caused by
``` julia
julia> @macroexpand@model test_defaults(x, n=length(x)) = x ~ MvNormal(zeros(n), I)
quote
function test_defaults(__model__::Model, __varinfo__::AbstractVarInfo, __context__::AbstractPPL.AbstractContext, x, n; )
...
end
begin
$(Expr(:meta, :doc))
function test_defaults(x, n = length(x); )
# This is the offending line.
return (Model)(test_defaults, NamedTuple{(:x, :n)}((x, n)), NamedTuple{(:n,)}((length(x),)))
end
end
end
```
And subsequently fixed in this PR, in which case the above is
```julia
julia> @macroexpand@model test_defaults(x, n=length(x)) = x ~ MvNormal(zeros(n), I)
quote
function test_defaults(__model__::Model, __varinfo__::AbstractVarInfo, __context__::AbstractPPL.AbstractContext, x, n; )
...
end
begin
$(Expr(:meta, :doc))
function test_defaults(x, n = length(x); )
# Now we respect the argument `n`.
return (Model)(test_defaults, NamedTuple{(:x, :n)}((x, n)), NamedTuple{(:n,)}((n,)))
end
end
end
```
Co-authored-by: Hong Ge <[email protected]>
0 commit comments