See https://github.com/JuliaLang/julia/issues/3738. In particular: "`Union` 
with static parameters is generally problematic… A few easy cases are 
handled by the greedy approximation I use, but it's easiest just to keep 
static parameters out of unions for now."

On Tuesday, October 20, 2015 at 10:45:15 AM UTC-4, Glen O wrote:
>
> On Wednesday, 21 October 2015 00:15:41 UTC+10, Matt Bauman wrote:
>>
>> On Tuesday, October 20, 2015 at 10:09:42 AM UTC-4, Glen O wrote:
>>>
>>> Seems to be something wrong with the dispatch system with Union...
>>>
>>
>> Yes, Unions with TypeVars can behave strangely when the elements aren't 
>> mutually exclusive.  I think it's just greedily matching the first thing it 
>> can. In this case it's always matching the `T` in `Union{T, 
>> AbstractArray{T}}` to the type of the very first argument, and then 
>> applying that to the remaining arguments, which explains why it works with 
>> a scalar first argument.
>>
>
> That doesn't explain how my test works -  if 
> dispatchtest{T}(x::Union{Array{T,1},T}) = "success"
> is called with dispatchtest([1,2]), it fails, even though T=Array{Int,1} 
> should match.
>

Reply via email to