Problem with replacing module and ambiguous methods

Initially, I wanted to create a structure similar to a linked list, but more complex, namely:

mutable struct Move
    data::Int64
    next_moves::Union{Array{Move, 1}, Nothing}
    Move(data) = new(data, nothing)
end

Next I faced this problem: “ERROR: LoadError: invalid redefinition of constant Move”. And with the help of the Julia community I found a solution - to create a module. I think, this is in some sense useless, because, in my opinion, module is needed only to create another namespace and to structure the code.

Finally, I added simple function, so final code:

module move

export Move

mutable struct Move
    data::Int64
    next_moves::Union{Array{Move, 1}, Nothing}
    Move(data) = new(data, nothing)
end

end

function my_func(x::Union{Nothing, move.Move})
    println("Hello world")
end

my_func(nothing)

There isn’t any problem with the first code run, but with the second…

WARNING: replacing module move.
ERROR: LoadError: MethodError: my_func(::Nothing) is ambiguous. Candidates:
my_func(x::Union{Nothing, Main.move.Move}) in Main at Path:14
my_func(x::Union{Nothing, Main.move.Move}) in Main at Path:14
Possible fix, define
my_func(::Nothing)

And I absolutely don’t understand, what is happening

P.S. Julia v.1.2.0, Atom v.1.39.0

maybe you should restart with a fresh shell. I can’t reproduce your problem.

1 Like

Yes, restart solves the problem. But I don’t want to restart after each code fix

do you know/use Revise?

1 Like