# LHS qualifier of const ignored by dispatch

**URL:** <https://discourse.julialang.org/t/lhs-qualifier-of-const-ignored-by-dispatch/5082>\
**Category:** General Usage\
**Created:** [July 26, 2017, 10:32pm UTC](https://discourse.julialang.org/t/lhs-qualifier-of-const-ignored-by-dispatch/5082 "2017-07-26T22:32:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jameson\_Quinn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson_quinn/32/1490_2.png) [@Jameson\_Quinn](https://discourse.julialang.org/u/Jameson_Quinn)\
**Post date:** [July 26, 2017, 10:32pm UTC](https://discourse.julialang.org/t/lhs-qualifier-of-const-ignored-by-dispatch/5082/1 "2017-07-26T22:32:31Z")

</div>

I have the following:

```julia
  const ScalarVariateVal = Real
  const ArrayVariateVal{N,VT<: ScalarVariateVal} = DenseArray{VT, N}
  const DictVariateVal{K,VT<: ScalarVariateVal} = Associative{K, VT} 
  const AbstractVariateVal{V<:ScalarVariateVal} = Union{V, (ArrayVariateVal{XX,V} where XX), (DictVariateVal{XX,V} where XX)}

```

And then, in another file:

```julia
valtype{VT}(x::AbstractVariateVal{VT}) = VT

```

The problem is that the `V<:ScalarVariateVal` in the definition of AbstractVariateVal seems to be getting lost somehow. That is, the above method for valtype is getting called with VT==DataType… but then, since DataType is its own type, that leads to infinite recursion.

I tried to add “where V\<:ScalarVariateVal” to each instance of V in the RHS definition of AbstractVariateVal, but that gives another error I don’t understand: “expected UnionAll, got Type{Union{Associative{XX,V} where XX where V\<:Real, DenseArray{V,XX} where XX where V\<:Real, Real}}”. Isn’t UnionAll the type for anything that starts “Type{Union{…”?

I can certainly find workarounds for these issues, but should I report them? Are they bugs in Julia, or just failures of my own understanding?

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [July 28, 2017, 3:09pm UTC](https://discourse.julialang.org/t/lhs-qualifier-of-const-ignored-by-dispatch/5082/2 "2017-07-28T15:09:05Z")

</div>

Best to post a fully reproducible example that somebody can paste into the REPL. It’s somewhat hard to say anything in the abstract.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [July 28, 2017, 3:18pm UTC](https://discourse.julialang.org/t/lhs-qualifier-of-const-ignored-by-dispatch/5082/3 "2017-07-28T15:18:27Z")

</div>

My guess is that the `V` in the `Union` is matching the “wrong” thing (wrong being not the thing you expect). `Union`s in parameterized functions are kinda tricky.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [July 28, 2017, 5:16pm UTC](https://discourse.julialang.org/t/lhs-qualifier-of-const-ignored-by-dispatch/5082/4 "2017-07-28T17:16:02Z")

</div>

Also just from the title, `const` does not affect any runtime behavior with a few exception of `ccall`, `cglobal`, `llvmcall` etc. It certainly must not affect dispatch.
