Skip to content
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

comprehension failure in global scope #8128

Closed
stevengj opened this issue Aug 25, 2014 · 3 comments
Closed

comprehension failure in global scope #8128

stevengj opened this issue Aug 25, 2014 · 3 comments

Comments

@stevengj
Copy link
Member

using Color
m = 2
[RGB(i/m,0,0) for i=1:m]

gives

`_convert` has no method matching _convert(::Type{RGB{Float64}}, ::RGB{Float64})
while loading In[15], in expression starting on line 2
 in convert at /home/juser/.julia/v0.3/Color/src/conversions.jl:32
 in setindex! at array.jl:307
 in anonymous at no file

changing m to const eliminates the problem, so I'm guessing that this is some type-inference problem with globals. But it doesn't seem like this should give an error in any case.

@simonster
Copy link
Member

I think this is a reduced test case:

abstract A{T}
immutable B{T<:Integer} <: A{T}; end
Base.convert(::Type{B}, c::B) = c
Base.convert{T}(::Type{B}, c::A{T}) = error("should not be called")

julia> @which convert(B{TypeVar(:T,Top)}, B{Int}())
convert(::Type{B{T<:Integer}},c::B{T<:Integer}) at none:3

julia> convert(B{TypeVar(:T,Top)}, B{Int}())
ERROR: should not be called
 in convert at none:4

There's clearly something weird going on since the method returned by @which is not actually the method that gets called. In the code for the comprehension it's also a bit weird that code_typed(RGB, (Any, Int, Int)) is inferred as RGB{T<:Top}, since RGB is constrained as RGB{T<:Fractional}.

@timholy
Copy link
Member

timholy commented Oct 8, 2014

Likely also the cause of #8618.

@jakebolewski
Copy link
Member

This is fixed now, due to the resolution of #8631

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants