nim-works / nimskull

An in development statically typed systems programming language; with sustainability at its core. We, the community of users, maintain it.
https://nim-works.github.io/nimskull/index.html
Other
279 stars 39 forks source link

Report error for foreign forward declared generic #1374

Closed zerbina closed 4 months ago

zerbina commented 4 months ago

Summary

Fix the compiler or backend crashing when using an incomplete generic procedure from another module. A proper compiler error is now reported in this case.

Fixes https://github.com/nim-works/nimskull/issues/1368.

Details

The issues can only occur in the presence of cyclic imports. Instantiating a generic routine registers it in the instantiating module, preventing its body from being patched when the generic routine is complete. Using the instantiation cache when completing a forward- declared generic won't work, since the module an instantiation comes from might be closed already.

Instead, this situation is now detected and an error is reported. No error is reported if no instantiation takes place (i.e., because the instantiation was cached already), meaning that previously working code stays working.

saem commented 4 months ago

/merge

github-actions[bot] commented 4 months ago

Merge requested by: @saem

Contents after the first section break of the PR description has been removed and preserved below:


## Notes for Reviewers * a simple solution to prevent the compiler from crashing * the rules around exporting incomplete generic procedures need to be re-evaluated at some point