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
275 stars 39 forks source link

fix(sem): crash with procedure with error used as argument #1443

Closed zerbina closed 1 month ago

zerbina commented 1 month ago

Summary

Fix a compiler crash when passing the name of a procedure with an error as an argument to another routine.

Details

Overloadable and overloaded procedure symbols forewent the nkError wrapping done by semSym, thus not preventing instantiation or later inspection by sempass2, crashing the compiler with an IndexDefect on attempting to access the symbol's AST.

Non-overloaded procedure symbols can be passed to semSym directly, which takes care of the wrapping. To handle overloaded symbols, sigmatch.paramTypesMatch passes the picked symbol to semExpr first, which subsequently calls semSym, also marking the symbols as used.

The problem with using semExpr in paramTypesMatch is that the returned nkError currently dismisses the overload, resulting in an unnecessary "type mismatch" compiler error (with nimsuggest, check, etc.).

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

saem commented 1 month ago

/merge

github-actions[bot] commented 1 month ago

Merge requested by: @saem

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


## Notes for Reviewers * the unnecessary error is not ideal, but better than a crash