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

raise might eat errors when used with strformat #112

Closed
alaviss opened this issue Dec 8, 2021 · 2 comments · Fixed by #1261
Closed

raise might eat errors when used with strformat #112

alaviss opened this issue Dec 8, 2021 · 2 comments · Fixed by #1261
Assignees
Labels
bug Something isn't working compiler/sem Related to semantic-analysis system of the compiler

Comments

@alaviss
Copy link
Contributor

alaviss commented Dec 8, 2021

Example

import std/strformat

proc exec(cmd: string, args: varargs[string]) =
  let x = @[cmd] & args
  raise newException(CatchableError):
    fmt"{x}"
  # Only referring to a "broken" variable would this issue happen

Actual Output

test.nim(5, 3) Error: only a 'ref object' can be raised

Expected Output

The real cause of the error (invalid expression for x) should show up instead

test.nim(4, 18) Error: type mismatch: got <seq[string], varargs[string]>
but expected one of:
proc `&`[T](x, y: seq[T]): seq[T]
  first type mismatch at position: 2
  required type for y: seq[T]
  but expression 'args' is of type: varargs[string]
proc `&`[T](x: T; y: seq[T]): seq[T]
  first type mismatch at position: 2
  required type for y: seq[T]
  but expression 'args' is of type: varargs[string]
proc `&`[T](x: seq[T]; y: T): seq[T]
  first type mismatch at position: 2
  required type for y: T
  but expression 'args' is of type: varargs[string]
5 other mismatching symbols have been suppressed; compile with --showAllMismatches:on to see them

expression: @[cmd] & args

Additional information

  • Mainline does not have this issue
@alaviss alaviss added the bug Something isn't working label Dec 8, 2021
@beef331
Copy link
Contributor

beef331 commented Dec 8, 2021

Error report order issue with --errorMax:0 the error is there just not presented first

/home/jason/nimskull/bin/abuse.nim(5, 3) Error: only a 'ref object' can be raised
/home/jason/nimskull/bin/abuse.nim(4, 18) Error: type mismatch: got <seq[string], varargs[string]>
but expected one of:
proc `&`[T](x, y: seq[T]): seq[T]
  first type mismatch at position: 2
  required type for y: seq[T]
  but expression 'args' is of type: varargs[string]
proc `&`[T](x: T; y: seq[T]): seq[T]
  first type mismatch at position: 2
  required type for y: seq[T]
  but expression 'args' is of type: varargs[string]
proc `&`[T](x: seq[T]; y: T): seq[T]
  first type mismatch at position: 2
  required type for y: T
  but expression 'args' is of type: varargs[string]
5 other mismatching symbols have been suppressed; compile with --showAllMismatches:on to see them

@zerbina zerbina self-assigned this Mar 29, 2024
@zerbina zerbina added the compiler/sem Related to semantic-analysis system of the compiler label Mar 29, 2024
github-merge-queue bot pushed a commit that referenced this issue Mar 30, 2024
## Summary

Fix errors in expressions within `raise` statements being hidden
behind an "only a 'ref object' can be raised" error.

Fixes #112 

## Details

* make `semRaise` `nkError`-aware (proper error propagation)
* don't modify input AST in `semRaise`
* replace `localReport` in `semRaise` with `nkError`; the necessary
  diagnostics corresponding to the legacy reports are introduced
@zerbina
Copy link
Collaborator

zerbina commented Mar 31, 2024

Fixed by #1261, errors are now properly propagated for raise statements.

@zerbina zerbina closed this as completed Mar 31, 2024
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.

3 participants