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

compiler crashes when using erroneous generic routine symbol as call argument #1384

Closed
zerbina opened this issue Jul 15, 2024 · 0 comments · Fixed by #1443
Closed

compiler crashes when using erroneous generic routine symbol as call argument #1384

zerbina opened this issue Jul 15, 2024 · 0 comments · Fixed by #1443
Labels
bug Something isn't working compiler/sem Related to semantic-analysis system of the compiler

Comments

@zerbina
Copy link
Collaborator

zerbina commented Jul 15, 2024

Example

proc generic[T](x: T) =
  missing # provoke the generic pre-pass to fail (via a symbol lookup error) 

proc f(p: proc(x: int)) =
  discard

f(generic) # <- instantiation is attempted even though the symbol is erroneous

Actual Output

Error: unhandled exception: field 'sons' is not accessible for type 'TNode' using 'kind = nkError' [FieldDefect]

Expected Output

Error: undeclared identifier: 'missing'

Possible Solution

Analyzing the expression goes through semExpr, but not semSym (which would have wrapped the symbol usage in an error), due to the symbol being a skProc.

If the symChoice call part of the nkIdent handling of semExpr results in a single symbol, the symbol can be checked (and wrapped in an error) early. For the case where a symbol-choice is returned, the error wrapping can only happen where the choice is ultimately resolved.

@zerbina zerbina added bug Something isn't working compiler/sem Related to semantic-analysis system of the compiler labels Jul 15, 2024
github-merge-queue bot pushed a commit that referenced this issue Sep 3, 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.
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
Development

Successfully merging a pull request may close this issue.

1 participant