libsyntax: fix infinite loop when recursively including modules

Fixes #7276