1
votes

So here is the code I have

abstract AbstractNode

type Edge
    source::AbstractNode
    target::AbstractNode

    Edge(source::AbstractNode, target::AbstractNode) = new(source, target)
    end

type Node <: AbstractNode
    edgeList::Vector{Edge}

    Node() = new([])
    end

a = Node()
b = Node()
edge = Edge(a,b)
push!(a.edgeList, edge)

If you run this code then a stores edge which itself stores a. In Python that doesn't cause a problem, but with Julia I enter a recursive loop and get a StackOverFlowError() (shout out! :-)). How do I resolve this?

1

1 Answers

4
votes

This issue has been fixed in Julia 0.3, i.e. I get

julia> push!(a.edgeList, edge)
1-element Array{Edge,1}:
 Edge(Node([Edge(#= circular reference =#)]),Node([]))

Here is the pull request that fixed this "bug" (which is a bug only in the sense of output - the datastructure itself is of course perfectly fine).