From aeb5e03fdfe6958e4f79d9ccc5b01b84b93371ff Mon Sep 17 00:00:00 2001 From: David Widmann Date: Fri, 11 Feb 2022 19:12:55 +0000 Subject: [PATCH] Fix `hasmissing` dispatches (#368) (#369) Fixes #368. --- Project.toml | 2 +- src/compiler.jl | 7 ++++--- test/compiler.jl | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index df3a621de..223032d63 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/compiler.jl b/src/compiler.jl index b9c7eead9..e851dd310 100644 --- a/src/compiler.jl +++ b/src/compiler.jl @@ -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) diff --git a/test/compiler.jl b/test/compiler.jl index 9dc81ff16..4b1530f11 100644 --- a/test/compiler.jl +++ b/test/compiler.jl @@ -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