TypeError in typeassert, expected

The problem with error messages is that many of them are not due to syntax errors, but inherently runtime phenomena.
Consider a function like:

function f(a, b)
    for i in a::b
        println(i)
    end
end

The call f(1, 4) fails, whereas f(1:4, UnitRange{Int}) succeeds.
f(eachindex(rand(4)), Base.OneTo{Int}) also succeeds, as well as f(3:0, OrdinalRange) and f(1,Int), but f(1:10, StepRange) fails.
This is of course an artificial example, but it illustrates a problem with catching errors in a meaningful way when types are determined at runtime.
It’s simply quite hard to give good runtime error texts when functions have been compiled, and the actual syntax which was in question no longer is easily available.