LHS qualifier of const ignored by dispatch

I have the following:

  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:

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?

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

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

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.