-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assertion failure in type system #22592
Comments
Minimal reproducer: f(::UnionAll) = nothing
f(::DataType) = nothing
f{T<:DataType}(::Type{T}) = nothing |
Workaround JuliaLang/julia#22592 by rearranging code
Seems to be fixed on master? @simonster could you confirm whether JLD2 works? |
On a debug build of current master, here's a case that triggers the same assertion: module CVS
abstract type Colorant{T,N} end
abstract type Color{T, N} <: Colorant{T,N} end
abstract type AbstractRGB{T} <: Color{T,3} end
AbstractGray{T} = Color{T,1}
MathTypes{T,C} = Union{AbstractRGB{T},AbstractGray{T}}
plus(a::AbstractGray, b::AbstractGray) = 1
plus(c::AbstractGray) = c
plus(a::MathTypes, b::MathTypes) = plus(promote(a, b)...)
end It's a stripped-down version of ColorVectorSpace. |
It seems to be a problem of type specificity between the unary variant and the binary
So it seems that the method table is being sorted like this (in order of "most specific to least specific"): plus(a::MathTypes, b::MathTypes) = plus(promote(a, b)...)
plus(c::AbstractGray) = c
plus(a::AbstractGray, b::AbstractGray) = 1 As evidence that this is correct, all I have to do is change the order of their definition to plus(a::AbstractGray, b::AbstractGray) = 1
plus(a::MathTypes, b::MathTypes) = plus(promote(a, b)...)
plus(c::AbstractGray) = c and then I don't trigger the assertion anymore, and the method table is julia> methods(CVS.plus)
# 3 methods for generic function "plus":
[1] plus(c::Main.CVS.Color{T,1} where T) in Main.CVS at /tmp/CVS.jl:13
[2] plus(a::Main.CVS.Color{T,1} where T, b::Main.CVS.Color{T,1} where T) in Main.CVS at /tmp/CVS.jl:11
[3] plus(a::Union{Main.CVS.AbstractRGB{T}, Main.CVS.Color{T,1}} where T, b::Union{Main.CVS.AbstractRGB{T}, Main.CVS.Color{T,1}} where T) in Main.CVS at /tmp/CVS.jl:12 |
We considered Union{A,B} more specific than B if A was more specific than B (but not a subtype of it). Clearly, it should not be.
I believe this was fixed a while ago; @simonster please reopen if you're still able to reproduce this. The ColorVectorSpace issue is separate, #29136. |
We considered Union{A,B} more specific than B if A was more specific than B (but not a subtype of it). Clearly, it should not be.
On JuliaIO/JLD2.jl@dfca1f0 (current JLD2 master) with 0.6 debug build:
The assertion failure occurs when loading this line. Appears to operate properly with a non-debug build.
The text was updated successfully, but these errors were encountered: