Jump to page: 1 2
Thread overview
[Issue 7529] New: IFTI does not support aliases
Feb 17, 2012
Kyle Foley
[Issue 7529] IFTI does not support template argument dependent template alias instances as parameter types
Feb 17, 2012
timon.gehr@gmx.ch
Feb 17, 2012
dawg@dawgfoto.de
Feb 17, 2012
timon.gehr@gmx.ch
Feb 17, 2012
timon.gehr@gmx.ch
Feb 17, 2012
dawg@dawgfoto.de
Feb 17, 2012
timon.gehr@gmx.ch
Feb 17, 2012
dawg@dawgfoto.de
Feb 17, 2012
timon.gehr@gmx.ch
Feb 17, 2012
Kenji Hara
Feb 17, 2012
timon.gehr@gmx.ch
Feb 17, 2012
dawg@dawgfoto.de
Feb 17, 2012
timon.gehr@gmx.ch
Feb 17, 2012
dawg@dawgfoto.de
Feb 17, 2012
Kenji Hara
Feb 17, 2012
timon.gehr@gmx.ch
Feb 17, 2012
timon.gehr@gmx.ch
Feb 17, 2012
dawg@dawgfoto.de
Feb 17, 2012
timon.gehr@gmx.ch
February 17, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529

           Summary: IFTI does not support aliases
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: kyfolee@gmail.com


--- Comment #0 from Kyle Foley <kyfolee@gmail.com> 2012-02-16 21:35:01 EST ---
DMD 2.058

template Type(T) { alias T Type; }
void f(T)(T, Type!(T)) {}

void main()
{
    f(0, 0); // fail
    f!(int)(0, 0); // success
}

---

.\ifti_alias.d(6): Error: template ifti_alias.f(T) does not match any function
template declaration
.\ifti_alias.d(6): Error: template ifti_alias.f(T) cannot deduce template
function from argument types !()(int,int)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 17, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529


timon.gehr@gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timon.gehr@gmx.ch
            Summary|IFTI does not support       |IFTI does not support
                   |aliases                     |template argument dependent
                   |                            |template alias instances as
                   |                            |parameter types
           Severity|normal                      |enhancement


--- Comment #1 from timon.gehr@gmx.ch 2012-02-16 20:23:46 PST ---
This is an enhancement, a very desirable one.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 17, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529


dawg@dawgfoto.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dawg@dawgfoto.de


--- Comment #2 from dawg@dawgfoto.de 2012-02-16 20:49:38 PST ---
The issue is what do you make of related cases.

// not deducible
void f(T)(Type!T) {}
f(0);

// ?
void f(T)(Type!T, T) {}
f(0, 0);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 17, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529



--- Comment #3 from timon.gehr@gmx.ch 2012-02-16 21:24:43 PST ---
Both of those(In reply to comment #2)
> The issue is what do you make of related cases.
> 
> // not deducible
> void f(T)(Type!T) {}
> f(0);
> 
> // ?
> void f(T)(Type!T, T) {}
> f(0, 0);

Both of those should work. The enhancement demands special treatment of templated aliases.

For example, this would work too:

template LList(T){alias Lazy!(List!T)) LList;}
alias f(T)(LList!T){}

f(new LList);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 17, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529



--- Comment #4 from timon.gehr@gmx.ch 2012-02-16 21:25:43 PST ---
I meant
void f(T)(LList!T){}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 17, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529



--- Comment #5 from dawg@dawgfoto.de 2012-02-16 22:03:04 PST ---
The reason why this works with structs but not with templates is that a struct preserves the full type information while an alias template transforms a type.

void bar(Ty)(Ty) { pragma(msg, Ty); }

struct SList(T) {}
template TList(T) { alias T TList; }

void main()
{
    bar(SList!int.init); // type SList!int => SList!int is preserved
    bar(TList!int.init); // type int       => TList!int is lost
}

Now if you take a function void foo(T)(TList!T) {} and gives you 'TList(T) =
int'.
What your asking for is an inverted template 'TList^-1(int) = T'.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 17, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529



--- Comment #6 from timon.gehr@gmx.ch 2012-02-17 04:34:10 PST ---
(In reply to comment #5)
> The reason why this works with structs but not with templates is that a struct preserves the full type information while an alias template transforms a type.
> 
> void bar(Ty)(Ty) { pragma(msg, Ty); }
> 
> struct SList(T) {}
> template TList(T) { alias T TList; }
> 
> void main()
> {
>     bar(SList!int.init); // type SList!int => SList!int is preserved
>     bar(TList!int.init); // type int       => TList!int is lost
> }
> 
> Now if you take a function void foo(T)(TList!T) {} and gives you 'TList(T) =
> int'.
> What your asking for is an inverted template 'TList^-1(int) = T'.

Well, yes. But only for a simple set of cases where this is workable. Basically the alias would need to be expanded before IFTI matching.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 17, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529



--- Comment #7 from dawg@dawgfoto.de 2012-02-17 06:52:19 PST ---
void foo(T)(Unsigned!T val)
{
}

foo(2u);

???

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 17, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529



--- Comment #8 from timon.gehr@gmx.ch 2012-02-17 06:54:08 PST ---
Unsigned is not an alias template. Your example is unrelated to this enhancement.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 17, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7529



--- Comment #9 from Kenji Hara <k.hara.pg@gmail.com> 2012-02-17 07:10:54 PST ---
I think this is invalid issue.
Reduced case:

void f(T)(T, T) { pragma(msg, T); }
void main()
{
  f(0L, 0);   // first argument is long, and second one is int
  // Error: template test.f(T) does not match any function template declaration
}

In IFTI, arguments don't have any dependencies each other about the deduction.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2