Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Sep 2, 2024

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 #1384.
Fixes #1442.

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.).
@zerbina zerbina added bug Something isn't working compiler/sem Related to semantic-analysis system of the compiler labels Sep 2, 2024
@saem
Copy link
Collaborator

saem commented Sep 2, 2024

/merge

Copy link

github-actions bot commented Sep 2, 2024

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

@chore-runner chore-runner bot enabled auto-merge September 2, 2024 21:14
@zerbina
Copy link
Collaborator Author

zerbina commented Sep 2, 2024

The problem with calling semSym in after symChoice is that markUsed is called on the symbols twice (once by symChoice, and once by semSym), which is what currently results in the nimsuggest test failures.

Either the error wrapping needs to be split out of semSym, or symChoice needs to stop marking a single symbol as used. The former is likely the better solution, at least for the moment.

`semSym` would call `markUsed` on the symbol again, resulting in a
duplicate usage being reported with `nimsuggest`.
@chore-runner chore-runner bot added this pull request to the merge queue Sep 3, 2024
Merged via the queue into nim-works:devel with commit 73b9136 Sep 3, 2024
35 checks passed
@zerbina zerbina deleted the sem-fix-symbol-error-propagation branch September 11, 2024 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler/sem Related to semantic-analysis system of the compiler
Projects
None yet
2 participants