Weird applicable behavior

mutable struct Coords
    x::Float64
    y::Float64
    z::Float64
end
Coords() = Coords(rand(), rand(), rand())

v = Coords()
println(v)
println(applicable(first, v))
println(first(v))

yields an (expected) error after passing (wrongly) the applicable test. What is wrong?

Coords(0.8974851346762911, 0.17094986513890453, 0.9623104755087182)
true
ERROR: LoadError: MethodError: no method matching iterate(::Coords)

applicable just checks if there is a type restriction preventing the function from running. It doesn’t check the full stack of everything that function calls.


julia> f(x) = g(x);

julia> g(x::Int) = 1;

julia> applicable(f, 1.0)
true
1 Like

Alas!