-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sem): errors in lambdas no longer crash (#1437)
## Summary Errors in lambdas requiring inference ( `proc(e: auto) = echo e` ), no longer crash the compiler. Instead errors within the lambda body are reported and lambda inference fails as it should. ## Details `semInferredLambda` failed to wrap its output when there were errors. This would reach `transf` and result in a compiler crash by hitting an `unreachable` assertion. Now errors in the body are reported immediately (to provide context for inference failure wrt matching the body) and AST output from the inference attempt is correctly wrapped such that inference appropriately fails. Fixes #1381 In addition, some minor refactoring was done to avoid shadowing the input parameter `n` and making it look like we were mutating the input. --------- Co-authored-by: zerbina <[email protected]>
- Loading branch information
Showing
3 changed files
with
43 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
tests/lang_callable/generics/tauto_inference_failure_due_to_body_error.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
discard """ | ||
description: "Fail lambda inference due to error within the body." | ||
errormsg: "undeclared identifier: 'i'" | ||
line: 13 | ||
""" | ||
|
||
# This is a regression test, ensure we report errors inside lambdas during | ||
# inference | ||
|
||
proc test(p: proc(x: int)) = | ||
discard | ||
|
||
test proc(e: auto) = i |