-
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 on unmatched
immediate
routines (#929)
## Summary Unmatched `immediate` `macro`s and `template`s within a generic context no longer result in a compiler error. ## Details Immediate macros and templates are not dispatched via `sigmatch` and instead `semgnrc` directly calls `evaltempl.evalTemplate`, in turn `evalTemplateArgs` is called which can produce an error if an incorrect number of arguments are provided. `evalTemplateArgs` is also used by `semMacroExpr`, so similar issues would also exist for macros. Now the error from `evalTemplateArgs` is immediately returned by `evalTemplate` and treated as a mismatch in `semgnrc.semGenericStmt`. Doing so prevents a compiler crash, attempt to access the sons of an error node. A test has been added as part of this change, which was originally from: zevv/npeg#68 (comment)
- Loading branch information
Showing
3 changed files
with
24 additions
and
1 deletion.
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
16 changes: 16 additions & 0 deletions
16
tests/lang_callable/overload/timmediate_meta_routine_mismatch.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,16 @@ | ||
discard """ | ||
action: reject | ||
description: "Ensure immediate macros/templates mismatches are reported" | ||
""" | ||
|
||
template unique(x, y: untyped) = | ||
## A template (macro would work too) that is not overloaded. | ||
# it's important that an argument is actually used within the template, in | ||
# order to force traveral of the actual arguments (it's lazy and driven by | ||
# the body). | ||
y | ||
|
||
proc test[T]() = | ||
unique("test") | ||
|
||
test() |