Hi everyone, I am having trouble calling a method that I have overridden. Here is an example:
module XXX
export hello
function hello()
println("XXX")
end
end
using XXX
t = function XXX.hello()
println("yyy")
end
t()
The result is:
WARNING: Method definition hello() in module XXX at test/overr.jl:4 overwritten in module Main at test/overr.jl:11.
ERROR: LoadError: MethodError: objects of type Void are not callable
Stacktrace:
[1] include_from_node1(::String) at ./loading.jl:569
[2] include(::String) at ./sysimg.jl:14
[3] process_options(::Base.JLOptions) at ./client.jl:305
[4] _start() at ./client.jl:371
while loading test/overr.jl, in expression starting on line 14
It means typeof(function XXX.hello() ...end) == Void, so when you assigned to t, it gets the value nothing, hence cannot be called. So @yuyichao was suggesting to either call directly XXX.hello(), or to assign the function to a variable like in t = XXX.hello before calling t().
That said, I don’t know why this form of method definition unexpectedly returns nothing rather than the function.
julia> module XXX
export hello
function hello()
println("XXX")
end
end
julia> using XXX
julia> t = function XXX.hello()
println("yyy")
end
julia> typeof(t)
Void
julia> XXX.hello()
yyy