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 : :

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

the second motoko file:

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

the third motoko file:

import user "./user";
import article "./article";

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.