Bug 20298 – Passing field alias to alias predicate doesn't work, predicate needs explicit instantiation

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-10-13T17:25:04Z
Last change time
2024-12-13T19:05:51Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Vladimir Panteleev
Moved to GitHub: dmd#19629 →

Comments

Comment #0 by dlang-bugzilla — 2019-10-13T17:25:04Z
///////////// test.d ///////////// struct S { int i; alias field = i; int fun(alias pred)() const { // Doesn't work: //return pred(field); // Works: alias ipred = pred!int; return ipred(field); } alias fun1 = fun!(i => i + 1); } ////////////////////////////////// Error is: test.d(9,14): Error: template `test.S.__lambda5` cannot deduce function from argument types `!()(const(int)) const`, candidates are: test.d(16,20): `__lambda5` test.d(16,15): Error: template instance `test.S.fun!((i) => i + 1)` error instantiating
Comment #1 by razvan.nitu1305 — 2019-10-15T12:37:10Z
Isn't the real bug here the fact that calling ipred passes compilation? As far as I could tell the lambda template instantion is inside the scope of the S struct => you cannot call it from fun, since fun may call only const functions and pred is mutable.
Comment #2 by dlang-bugzilla — 2019-10-15T12:59:51Z
Thanks for looking at this! (In reply to RazvanN from comment #1) > As > far as I could tell the lambda template instantion is inside the scope of > the S struct Hmm! But, shouldn't it infer that since it doesn't access anything other than its arguments, it should not have a context? I see that ipred is typed as a function not delegate. > you cannot call it from fun, since fun may call only const > functions and pred is mutable. Thanks, I actually didn't realize that fun being const was a crucial part of this. I guess the error message could be better.
Comment #3 by robert.schadek — 2024-12-13T19:05:51Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19629 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB