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): missed discard in try/finally errors #995

Merged
merged 5 commits into from
Oct 24, 2023

Conversation

saem
Copy link
Collaborator

@saem saem commented Oct 24, 2023

Summary

A missing discard in a try/finally no longer crashes the compiler
and emits an error as it should.

Details

The discardCheck used to ensure expressions are used or void did not
traverse try appropriately. Instead of looking at the last expression
in the last except or try branch, it would look at the last branch,
even if that was a finally. This led to incomplete data being sent for
error reporting, which ultimately led to an NPE.

Along with the fix a regression test has been added.

## Summary

A missing `discard` in a `try/finally` no longer crashes the compiler
and emits an error as it should.

## Details

The `discardCheck` used to ensure expressions are used or `void` did not
traverse `try` appropriately. Instead of looking at the last expression
in the last `except` or `try` branch, it would look at the last branch,
even if that was a `finally`. This led to incomplete data being sent for
error reporting, which ultimately led to an NPE.

Along with the fix a regression test has been added.
@saem saem added bug Something isn't working compiler/sem Related to semantic-analysis system of the compiler labels Oct 24, 2023
Copy link
Collaborator

@zerbina zerbina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The node indexing changes in semTry need to be reverted, otherwise the following:

try:
  discard
except:
  1

is no longer reported as being incorrect. This is because the type of both nkExceptBranch and nkFinally is always nil, meaning that the discardCheck call will do nothing.

compiler/sem/semstmts.nim Outdated Show resolved Hide resolved
compiler/sem/semstmts.nim Outdated Show resolved Hide resolved
compiler/sem/semstmts.nim Outdated Show resolved Hide resolved
@saem
Copy link
Collaborator Author

saem commented Oct 24, 2023

@zerbina I added an extra test to avoid regressing on the example provided -- nice catch.

@saem
Copy link
Collaborator Author

saem commented Oct 24, 2023

/merge

@github-actions
Copy link

Merge requested by: @saem

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


Notes for Reviewers

@chore-runner chore-runner bot added this pull request to the merge queue Oct 24, 2023
Merged via the queue into nim-works:devel with commit 4a6621e Oct 24, 2023
18 checks passed
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 this pull request may close these issues.

2 participants