Bug 17401 – type inference broken when F and Parameters!F are used

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-05-16T06:16:53Z
Last change time
2024-12-13T18:52:11Z
Keywords
industry
Assigned to
No Owner
Creator
Tomer Filiba (weka)
Moved to GitHub: dmd#19251 →

Comments

Comment #0 by tomer — 2017-05-16T06:16:53Z
dmd v2.074.0 on ubuntu 14.04 ------------------- import std.traits: Parameters; void f(int x) {} void wrap1(R, T...)(R function(T) fn, T args) {} void wrap2(alias F)(Parameters!F args) {} void wrap3(F)(F fn, Parameters!F args) {} void wrap4(F)(F* fn, Parameters!F args) {} void main() { int x; wrap1(&f, x); // ok wrap2!f(x); // ok wrap3(&f, x); // Error: template wrap3 cannot deduce function from argument types !()(void function(int x), int), candidates are: // wrap3(F)(F fn, Parameters!F args) wrap4!(typeof(f))(&f, x); // ok -- explicit typeof wrap4(&f, x); // same error }
Comment #1 by tomer — 2017-05-16T06:19:26Z
the first version (wrap1) would have been OK, but it cannot be used with `ref`/`scope`/`lazy` etc, as these would be lost when using `T...`. so void f(ref int x) {} int x; wrap1(&f, x); // void function(int) != void function(ref int)
Comment #2 by dlang-bugzilla — 2017-05-16T07:02:02Z
Mixing IFTI arguments and arguments derived from IFTI arguments is currently not supported. (It was surely reported before in another issue.) A workaround is: void wrap5(F, Args...)(F fn, Args args) if (is(Args == Parameters!F)) {} wrap5(&f, x); > void f(ref int x) {} > int x; > wrap1(&f, x); // void function(int) != void function(ref int) Just for ref, "auto ref" usually suffices. BTW, I noticed you added the industry keyword. If you haven't already, consider adding your company to http://dlang.org/orgs-using-d.html.
Comment #3 by tomer — 2017-05-16T07:15:45Z
I'm from weka (updated my email to the company's email thanks to your advice)
Comment #4 by bugzilla — 2020-03-27T21:13:13Z
Minimal test case: ---- void f(int x) {} void wrap(F)(F fn, S!F args) {} struct S(F) { } void test() { wrap(&f, 1); } ---- test.d(9): Error: template `test2.wrap` cannot deduce function from argument types `!()(void function(int x), int)`, candidates are: test.d(4): `test2.wrap(F)(F fn, S!F args)`
Comment #5 by contact — 2023-01-02T11:53:32Z
This seem to be an issue with delegates too.
Comment #6 by robert.schadek — 2024-12-13T18:52:11Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19251 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB