-
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): crash with procedure with error used as argument (#1443)
## 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.
- Loading branch information
Showing
5 changed files
with
54 additions
and
2 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
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,15 @@ | ||
discard """ | ||
description: ''' | ||
Ensure that generic procedure symbols are wrapped in an error, when used | ||
in an argument context | ||
''' | ||
action: reject | ||
matrix: "--errorMax:100" | ||
""" | ||
|
||
proc call(p: proc(x: int)) = discard | ||
|
||
proc withError[T](x: T) = | ||
missing | ||
|
||
call(withError) # <- this crashed the compiler |
18 changes: 18 additions & 0 deletions
18
tests/error_propagation/toverloaded_proc_sym_as_argument.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,18 @@ | ||
discard """ | ||
description: ''' | ||
Ensure that overloaded procedure symbols are wrapped in an error, when | ||
used in an argument context | ||
''' | ||
action: reject | ||
matrix: "--errorMax:100" | ||
""" | ||
|
||
proc call(p: proc()) = discard | ||
|
||
proc withError() = | ||
missing | ||
|
||
proc withError(a: int) = # <- this overload is not picked below | ||
discard | ||
|
||
call(withError) # <- this crashed the compiler |
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,15 @@ | ||
discard """ | ||
description: ''' | ||
Ensure that procedure symbols are wrapped in an error, when used in an | ||
argument context | ||
''' | ||
action: reject | ||
matrix: "--errorMax:100" | ||
""" | ||
|
||
proc call(p: proc()) = discard | ||
|
||
proc withError() = | ||
missing | ||
|
||
call(withError) # <- this crashed the compiler |