-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
wrong error messages (undeclared identifier) on type mismatch of another error when untyped followed by typed params #9620
Comments
reduced: when true:
# Error: undeclared identifier: 'i'
template fn(index: untyped, length: int{lvalue}, body: untyped) = discard
var x = @[1]
fn(i, len(x)): discard further reduced, which shows title is wrong: when true:
template fn(a: untyped, b: int) = discard
fn(nonexistant, 1.0) this is a consequence of current sigmatch implementation for untyped params, which trigger semcheck for untyped params when not all arguments are untyped (IIUC this used to be what immediate templates were). see also: https://nim-lang.github.io/Nim/manual.html#overloading-resolution-lazy-type-resolution-for-untyped this is related to #14827 but definitely different |
…or (#23984) fixes #8697, fixes #9620, fixes #23265 When matching a `template` with an `untyped` argument fails because of a mismatching typed argument, `presentFailedCandidates` tries to sem every single argument to show their types, but trying to type the `untyped` argument can fail if it's supposed to use an injected symbol, so we get an unrelated error message like "undeclared identifier". Instead we use `tryExpr` as the comment suggests, setting the type to `untyped` if it fails to compile. We could also maybe check if an `untyped` argument is expected in its place and not try to compile the expression if it is but this would require a bit of reorganizing the code here and IMO it's better to have the information of what type it would be if it can be typed. (cherry picked from commit 34719ca)
In the same vein as #9414, using a parameter constraint like {lvalue} does not work with identifier injection.
Test case:
Error: undeclared identifier: 'i'
Removing the lvalue constraint makes the code compile.
The text was updated successfully, but these errors were encountered: