Closed zerbina closed 4 months ago
/merge
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
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.