Skip to content

Commit

Permalink
Fix hasmissing dispatches (#368) (#369)
Browse files Browse the repository at this point in the history
Fixes #368.
  • Loading branch information
devmotion committed Feb 11, 2022
1 parent cc3025b commit aeb5e03
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
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.17.4"
version = "0.17.5"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
7 changes: 4 additions & 3 deletions src/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,10 @@ function make_returns_explicit!(body::Expr)
end

const FloatOrArrayType = Type{<:Union{AbstractFloat,AbstractArray}}
hasmissing(T::Type{<:AbstractArray{TA}}) where {TA<:AbstractArray} = hasmissing(TA)
hasmissing(T::Type{<:AbstractArray{>:Missing}}) = true
hasmissing(T::Type) = false
hasmissing(::Type) = false
hasmissing(::Type{>:Missing}) = true
hasmissing(::Type{<:AbstractArray{TA}}) where {TA} = hasmissing(TA)
hasmissing(::Type{Union{}}) = false # issue #368

"""
build_output(modelinfo, linenumbernode)
Expand Down
14 changes: 14 additions & 0 deletions test/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -588,4 +588,18 @@ end
@model outer() = @submodel x = inner()
@test outer()() isa Real
end

@testset "issue #368: hasmissing dispatch" begin
@test !DynamicPPL.hasmissing(typeof(Union{}[]))

# (nested) arrays with `Missing` eltypes
@test DynamicPPL.hasmissing(Vector{Union{Missing,Float64}})
@test DynamicPPL.hasmissing(Matrix{Union{Missing,Real}})
@test DynamicPPL.hasmissing(Vector{Matrix{Union{Missing,Float32}}})

# no `Missing`
@test !DynamicPPL.hasmissing(Vector{Float64})
@test !DynamicPPL.hasmissing(Matrix{Real})
@test !DynamicPPL.hasmissing(Vector{Matrix{Float32}})
end
end

2 comments on commit aeb5e03

@devmotion
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/54482

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.17.5 -m "<description of version>" aeb5e03fdfe6958e4f79d9ccc5b01b84b93371ff
git push origin v0.17.5

Please sign in to comment.