Julia - Inserting subtype element to array of supertype
julia
Solution
This seemed to be a problem due to having older compiled code still in the scope (see the comments). The easiest way to handle this is just to restart Julia.
Problem
I'm totally new to Julia, I have the following class hierarchy, when I insert an instance of the subtype `NonTerminal` into an array that's declared of the supertype `GrammarElement`, an exception is thrown ``` GrammarElement |--> Terminal |--> Nonterminal ``` As such ``` abstract GrammarElement type Terminal <: GrammarElement name::String end type NonTerminal <: GrammarElement name::String rule::Array{GrammarElement,1} function NonTerminal(name::String) new(name,GrammarElement[]) end end function and_with!(t,e) push!(t.rule,e) end ``` But when I use the `and_with!` function the test throws an exception ``` @testset "Test" begin r = NonTerminal("A") t=Terminal("B") and_with!(r,t) end ``` Failing on ( removed lots of garbage in the message ) ``` TestFirst: Error During Test Got an exception of type MethodError outside of a @test MethodError: Cannot `convert` an object of type Terminal to an object of type GrammarElement This may have arisen from a call to the constructor GrammarElement(...) ``` - Why isn't that conversion possible? - How can I solve this? - Is it event useful to declare the parent type? I'm aware that julia is mainly for scientific computing and not creating grammar parsers, but it should do the job and I'm learning it with that project