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): analysis considers nested noreturn #1450

Merged
merged 5 commits into from
Sep 7, 2024

Conversation

saem
Copy link
Collaborator

@saem saem commented Sep 6, 2024

Summary

No-return analysis ensures that nested final expressions (
block/case/if/try ) are accounted for no-return itself.

Details

Prior to this change if the last expression within a greater expression
was a no-return expression it would not be deemed as such if it was a
block/case/if/try , instead errors would be raised related to discard
checks or that path not resulting in the correct type.

For example, the following would result in an error where 0 must be
used or discarded:

proc foo() =
  let x =
    if false: 10
    else:
      block:
        return

Fixes #1440

@saem saem added bug Something isn't working compiler/sem Related to semantic-analysis system of the compiler labels Sep 6, 2024
@saem saem changed the title Saem move and fix ends in no return fix(sem): analysis considers nested noreturns Sep 6, 2024
compiler/ast/ast_query.nim Outdated Show resolved Hide resolved
compiler/ast/ast_query.nim Outdated Show resolved Hide resolved
tests/lang_exprs/tnoreturn_nested.nim Outdated Show resolved Hide resolved
compiler/ast/ast_query.nim Outdated Show resolved Hide resolved
- quoting test description used double quotes, need triple-double-quotes
  - surfaced a testament bug that silently ignores error on test joining
- fix nested `case` test
- clean-up `endsInNoReturn` docs
- fix nested checking, both checking `.typ` field with `isEmptyType` and focus on stmt variants of nodes

Co-authored-by: zerbina <[email protected]>
@saem saem changed the title fix(sem): analysis considers nested noreturns fix(sem): analysis considers nested noreturn Sep 7, 2024
@saem
Copy link
Collaborator Author

saem commented Sep 7, 2024

/merge

Copy link

github-actions bot commented Sep 7, 2024

Merge requested by: @saem

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


Notes for Reviewers

  • it's cleaner than I thought
  • let me know if there is a better module to use than ast_query, trees didn't seem right

@chore-runner chore-runner bot added this pull request to the merge queue Sep 7, 2024
Merged via the queue into nim-works:devel with commit 4feef40 Sep 7, 2024
35 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.

raise within a nested if invalidate the outer if-expression
2 participants