I'm currently writing a compiler for a new language and I'm struggling with the linking aspect of new Types when there exists a circular reference.
I've created a dependency tree so that I can compile the Types in the order of their dependencies which seemed to have fixed my problem... that is until I hit circular references like an example below (posted in c#):
public class A
{
public A() { var b = new B(); }
}
public class B
{
public B() { var a = new A(); }
}
My limitation is that I can only create 1 Type at a time, and in the case of circular references, either A needs to be created first, or B needs to be created first, both of which poses the problem that I can't create either unless it's dependencies are first created!
How do compilers overcome this?