D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2778 - alias this + IFTI doesn't work.
Summary: alias this + IFTI doesn't work.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
: 6569 (view as issue list)
Depends on:
Blocks:
 
Reported: 2009-04-01 12:03 UTC by David Simcha
Modified: 2015-06-09 01:18 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description David Simcha 2009-04-01 12:03:38 UTC
DMD 2.027 can't implicitly instantiate templates properly based on implicit conversions via alias this.

import std.stdio;

struct ArrayWrapper(T) {
    T[] data;
    alias data this;
}

void doStuffTempl(T)(T[] data) {}

void doStuffFunc(int[] data) {}

void main() {
    ArrayWrapper!(int) foo;
    doStuffFunc(foo);  // Works.
    doStuffTempl!(int)(foo);  // Works.

    // Error: template test.doStuffTempl(T) does not match any function
    // template declaration
    // Error: template test.doStuffTempl(T) cannot deduce
    // template function from argument types !()(ArrayWrapper!(int))
    doStuffTempl(foo);
}
Comment 2 Kenji Hara 2011-10-23 22:46:19 UTC
*** Issue 6569 has been marked as a duplicate of this issue. ***
Comment 3 Steven Schveighoffer 2011-10-24 08:46:32 UTC
(In reply to comment #1)
> http://d.puremagic.com/issues/show_bug.cgi?id=2778

Nice reference :)

Think you meant:

https://github.com/D-Programming-Language/dmd/pull/472
Comment 5 Kenji Hara 2011-11-02 04:47:30 UTC
I found a lack of my patch.

Code:
----
inout(T) [n] id(T, size_t n)(inout(T) [n] v){ return v; }

void main()
{
    static struct S
    {
        ubyte[3] val = [1,2,3];
        @property ref void[3] get(){ return *cast(void[3]*)&val; }
        alias get this;
    }
    S s;
    id(s);
}

Output:
----
test.d(18): Error: template test.id(T,uint n) does not match any function template declaration
test.d(18): Error: template test.id(T,uint n) cannot deduce template function from argument types !()(S)

Additional patch for repair it:
https://github.com/D-Programming-Language/dmd/pull/487