Bug 11907 – No undeclared identifier error in lambda alias argument

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-01-12T03:02:46Z
Last change time
2024-12-13T18:15:59Z
Keywords
diagnostic
Assigned to
No Owner
Creator
Peter Alexander
See also
https://issues.dlang.org/show_bug.cgi?id=14217
Moved to GitHub: dmd#18756 →

Comments

Comment #0 by peter.alexander.au — 2014-01-12T03:02:46Z
void f(alias a)() if (is(typeof(a()))) {} void main() { f!(x => blarg); } This gives the error: foo.d(5): Error: template instance f!((x) => blarg) does not match template declaration f(alias a)() if (is(typeof(a()))) Ideally, the error would be: foo.d(5): Error: undeclared identifier 'blarg' This comes up all the time when using predicates on Phobos functions when you forget an import or just have a typo.
Comment #1 by b2.temp — 2020-07-04T17:36:22Z
the diagnostic is better nowdays: --- /tmp/temp_7F0C787490B0.d(5,5): Error: template instance `temp_7F0C787490B0.main.f!((x) => blarg)` does not match template declaration `f(alias a)()` with `a = __lambda1` must satisfy the following constraint: ` is(typeof(a()))` --- good enough to close ?
Comment #2 by nick — 2023-02-01T21:41:16Z
*** Issue 23663 has been marked as a duplicate of this issue. ***
Comment #3 by nick — 2023-02-01T21:52:48Z
Note: issue also applies when constraint is `__traits(compiles, a())`. > Ideally, the error would be: foo.d(5): Error: undeclared identifier 'blarg' The problem is that the lambda is a template, and templates aren't semantically analyzed until instantiated. If the constraint wasn't there then the body would likely instantiate the lambda somewhere and produce the desired error. In this case the lambda is trivial and some kind of analysis without types could detect the error, but not in the general case where the lambda doesn't compile for other reasons, e.g. `x => x.typo`. As a workaround, the constraint expression could be moved to a `static if` test in the body.
Comment #4 by robert.schadek — 2024-12-13T18:15:59Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18756 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB