When referring to self i.e. the current resource from a method parameter or result then this causes a stack overflow in the type resolver. The issue is caused by not having the resource name cached when we first encounter it and since it's a recursive reference we spin into a stack overflow.
Reproduction
interface foo {
resource a {
constructor() -> a
}
}
Solution
Refactor the resolver to a 2 stage setup:
- resolve all the names, check for duplicate or undefined names
- expand all the type definitions
This way, during type expansion we already have a reference to the resource and are not infinitely trying to resolve the name.