# Julia v1.1 Language changes: ambiguities

**URL:** <https://discourse.julialang.org/t/julia-v1-1-language-changes-ambiguities/22695>\
**Category:** Internals & Design\
**Tags:** documentation\
**Created:** [April 3, 2019, 2:24pm UTC](https://discourse.julialang.org/t/julia-v1-1-language-changes-ambiguities/22695 "2019-04-03T14:24:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxchendt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxchendt/32/42976_2.png) [@maxchendt](https://discourse.julialang.org/u/maxchendt)\
**Post date:** [April 3, 2019, 2:24pm UTC](https://discourse.julialang.org/t/julia-v1-1-language-changes-ambiguities/22695/1 "2019-04-03T14:24:06Z")

</div>

[https://docs.julialang.org/en/v1/NEWS/](https://docs.julialang.org/en/v1/NEWS/)

- Method signatures such as `f(::Type{T}, ::T) where {T <: X}` and `f(::Type{X}, ::Any)` are now considered ambiguous. Previously a bug caused the first one to be considered more specific in some cases ([#30160](https://github.com/JuliaLang/julia/issues/30160)).

Should the `f(::Type{T}, ::T) where {T <: X}` be ` f(::Type{T}, ::Any) where {T <: X}`, change the second argument from `::T` to `::Any`

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [April 3, 2019, 2:29pm UTC](https://discourse.julialang.org/t/julia-v1-1-language-changes-ambiguities/22695/2 "2019-04-03T14:29:51Z")

</div>

No, I believe that description is correct — it matches [the tests that were added in the same commit](https://github.com/JuliaLang/julia/pull/30160/files#diff-07ba12e1eb4b0690c95a612d607c8c04R263).

---

<div class="post-metadata">

**Author:** ![maxchendt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxchendt/32/42976_2.png) [@maxchendt](https://discourse.julialang.org/u/maxchendt)\
**Post date:** [April 3, 2019, 3:36pm UTC](https://discourse.julialang.org/t/julia-v1-1-language-changes-ambiguities/22695/3 "2019-04-03T15:36:32Z")

</div>

I am thinking that “the first one to be considered more specific” is more understandable.  
Would you please explain why the change?

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [April 3, 2019, 5:41pm UTC](https://discourse.julialang.org/t/julia-v1-1-language-changes-ambiguities/22695/4 "2019-04-03T17:41:12Z")

</div>

I’m perhaps not the best person to do so, but I reason about this as a case where one arg is more specific and the other arg is less specific. In this concrete case:

```julia
f(::Type{T}, ::T) where {T<:BitArray} = 1
f(::Type{BitArray}, ::Any) = 2

julia> f(BitArray, trues(3))
ERROR: MethodError: f(::Type{BitArray}, ::BitArray{1}) is ambiguous. Candidates:
  f(::Type{BitArray}, ::Any) in Main at REPL[2]:1
  f(::Type{T}, ::T) where T<:BitArray in Main at REPL[1]:1
Possible fix, define
  f(::Type{BitArray}, ::BitArray)

```

In other circumstances, `::Type{BitArray}` is more specific than `::Type{T} where {T <: BitArray}`:

```julia
g(::Type{BitArray}) = 1
g(::Type{T}) where {T<:BitArray} = 2

julia> g(BitArray)
1

```

But the `::Any` is less specific than the matching `::T`. Thus we have an ambiguity — one argument is more specific but the other is less.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [April 3, 2019, 6:57pm UTC](https://discourse.julialang.org/t/julia-v1-1-language-changes-ambiguities/22695/5 "2019-04-03T18:57:15Z")

</div>

The test case added in the pull request seems to make the issue fairly clear:

> <https://github.com/JuliaLang/julia/pull/30160#issuecomment-442688809>
>
> After this, transitivity holds for all \`convert\` methods. Fortunately, this leav…es all existing specificity and ambiguity tests passing, so this is potentially backportable if PkgEval agrees. Unfortunately, there are more transitivity failures in other functions (that I will soon address in another PR), and so far the fix for them seems to unavoidably change ambiguities.
> 
> Fixes #30114.

The method specificity relation really ought to be a partial order, and in particular, it should be transitive. There are certain cases where it fails to be transitive, and this change fixes one of those failures of transitivity. Was there a specific reason you were concerned about this change? Do you have code that is affected by it?

---

<div class="post-metadata">

**Author:** ![maxchendt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxchendt/32/42976_2.png) [@maxchendt](https://discourse.julialang.org/u/maxchendt)\
**Post date:** [April 4, 2019, 12:05am UTC](https://discourse.julialang.org/t/julia-v1-1-language-changes-ambiguities/22695/6 "2019-04-04T00:05:02Z")

</div>

Thanks for the reply!  
I am a beginner, no code affected by this.  
I just like to know a bit (if possible) on the ‘counter-intuitive’ points.
