I would like to thank mauro3, tkoolen for helping me solve my issue. Here is the simplified version on Repl.it.
I also experience some weird issues with import
ing. For example, I have two include files:
include("splash_scene.jl")
include("game_scene.jl")
both perform the same import statements:
import .Ranger.Nodes:
transition, get_replacement, visit
If I forget to import visit
in either one of the files I get this warning:
WARNING: import of Nodes.visit into Main conflicts with an existing identifier; ignored.
And as a result, the abstract overload is called instead. This is unexpected and in addition I don’t know why Julia issues this. It is true that I should only have only one import for both files—which is what I did to make sure there isn’t an inconsistency—but still it would be nice if Julia could somehow give a better clue to the problem. It took me 20 minutes to realize what the bug was. Basically, if you have this:
import .Ranger.Nodes:
transition, get_replacement, visit
... more code and some includes()
import .Ranger.Nodes:
transition, get_replacement #<--- missing visit import
You will get a warning.
Anyway, I am still learning Julia and I enjoy the language even with a few errors on my part.
The code-in-progress in on Github if you are interested.
Below is a stripped down example with two lines marked important
:
module Ranger
module Nodes
# This is important piece #1
function transition end
# Simple demo node for example ----------
abstract type AbstractNode end
mutable struct Node <: AbstractNode
x::Float64
end
crossnode = Node(1.0)
# -------------------------------------
function visit()
transition(crossnode)
end
end
end
# Demo engine
module Engine
using ..Ranger.Nodes:
visit
function run()
visit()
end
end
# ------------------
using .Ranger.Nodes:
AbstractNode, Node
# This is the important piece #2
import .Ranger.Nodes:
transition
function transition(node::AbstractNode)
println("abstract node transition")
end
function transition(node::Node)
println("node transition")
end
# -------------------------
using .Engine:
run
function go()
run()
end
go()