Stack Overflow : Caused by Motoko Struct circular import

Environment :
Ubuntu 20.04
Language : Motoko
Error Message:

Building canisters to check they build ok. Canister IDs might be hard coded.
Building canisters...

thread 'main' has overflowed its stack
fatal runtime error: stack overflow

You can recurrent the bug using the following code:
the first motoko file :
user.mo :

import article "./article";
module {
  type article = article.article;
  public type user = {
    name : Text;
    article : article;
  };
};

the second motoko file:
article.mo:

import user "./user";
module{
  type user = user.user;
  public type article = {
    name : Text;
    u : user;
  };
};

the third motoko file:

import user "./user";
import article "./article";
actor{
};

Thanks for the bug report. I’ll file an issue.

1 Like

Just to set the right expectations: cyclic imports are not allowed in Motoko. But they should produce a proper error, not crash the compiler.

2 Likes