https://github.com/JuliaLang/julia/issues/15120

Am Dienstag, 16. Februar 2016 22:54:54 UTC+1 schrieb Cedric St-Jean:
>
> That looks like a bug to me. I couldn't find any github issue covering it, 
> maybe you should submit one? 
>
> On Tuesday, February 16, 2016 at 10:01:05 AM UTC-5, Helge Eichhorn wrote:
>>
>> When I run the following code
>>
>> type A
>>     v::Float64
>> end
>>
>> type B
>>     v::Float64
>> end
>>
>> Base.convert(::Type{A}, b::B) = A(b.v/2)
>> b = B(12)
>> A(b)
>>
>> it fails with this error message because the implicit constructor is 
>> called.
>>
>> LoadError: MethodError: `convert` has no method matching 
>> convert(::Type{Float64}, ::B)
>> This may have arisen from a call to the constructor Float64(...),
>> since type constructors fall back to convert methods.
>> Closest candidates are:
>>   call{T}(::Type{T}, ::Any)
>>   convert(::Type{Float64}, !Matched::Int8)
>>   convert(::Type{Float64}, !Matched::Int16)
>>   ...
>> while loading In[1], in expression starting on line 11
>>
>>  in call at In[1]:2
>>
>>
>> Since the manual said "defining Base.convert(::Type{T}, args...) = 
>> ...automatically 
>> defines a constructor T(args...) = ....", I expected this to work.
>> If I define a convert method for a built-in type like Float64, it works. 
>> Am I doing something wrong or is this intended? If so, it should be clearly 
>> stated in the manual.
>>
>

Reply via email to