Thread overview
[Issue 1454] New: IFTI cant deduce parameter if alias argument used
Aug 30, 2007
d-bugmail
Aug 30, 2007
d-bugmail
Jan 29, 2008
d-bugmail
Feb 21, 2008
d-bugmail
Feb 21, 2008
d-bugmail
Feb 21, 2008
d-bugmail
Feb 21, 2008
d-bugmail
Feb 22, 2008
d-bugmail
Mar 07, 2008
d-bugmail
August 30, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1454

           Summary: IFTI cant  deduce parameter if alias argument used
           Product: D
           Version: 1.020
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: wbaxter@gmail.com


If you have a templated struct like
  struct Base(T) {}

and you create an alias of that
  alias Base Alias;

Then using the alias as an argument will confuse IFTI:
  void foo(T)(Alias!(T) x) { }

  Alias!(float) b;
  Alias!(float) a;
  foo(b);  // IFTI fails
  foo(a);  // IFTI fails

  foo!(float)(b) // ok
  foo!(float)(a) // ok

IFTI works fine for both if Base!(T) is used as the function argument.

Why would you want to do this? I'm trying to port some C++ code.  This code uses a lot of trivial struct inheritance to create a related set of value types (basically iterator types).  They all derive from one struct Base(T), and the derived things don't actually add anything new.  The derivation is used only to get a distinct type with a common ancestor.  So I'm trying to at least preserve the type structure in anticipation of the day when D gets a better way to do this.


-- 

August 30, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1454





------- Comment #1 from wbaxter@gmail.com  2007-08-29 20:41 -------
Created an attachment (id=173)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=173&action=view)
Test program


-- 

January 29, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1454





------- Comment #2 from burton-radons@shaw.ca  2008-01-29 16:34 -------
Here's a simpler example showing what appears to be the same problem:

        template A (T)
        {
                alias T A;
        }

        void func (T) (A! (T) a)
        {
        }

        void main ()
        {
                func (4);
        }

This fails compilation in DMD 1.026 with:

        template d.array.func(T) does not match any template declaration
        template d.array.func(T) cannot deduce template function from argument
types (int)

There is no workaround, this is bad!


-- 

February 21, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1454


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




------- Comment #3 from bugzilla@digitalmars.com  2008-02-21 00:59 -------
Consider the following more general case:

  template A(T) { alias R A; }
  void func(T)(A!(T).R a) { }
  void main() { func (4); }

So the call tells you that A!(T).R should be int. You need to (1) find the set
of Ts that satisfy the condition, and (2) prove that that set is { int }. I'm
not sure this is tractable, and even if it were, there's a bit too much AI
involved to make this a practical language feature.

(Thanks to Andrei for helping me with this)

C++ is not capable of doing this, either. Here's an example:

template<class T> struct Bar
{
    typedef T a;
};

template<class T> void foo(Bar<T>::A a) { }

void main()
{
    foo(3);
}


-- 

February 21, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1454





------- Comment #4 from bugzilla@digitalmars.com  2008-02-21 01:03 -------
*** Bug 1848 has been marked as a duplicate of this bug. ***


-- 

February 21, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1454





------- Comment #5 from bugzilla@digitalmars.com  2008-02-21 01:05 -------
*** Bug 1661 has been marked as a duplicate of this bug. ***


-- 

February 21, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1454


wbaxter@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |




------- Comment #6 from wbaxter@gmail.com  2008-02-21 02:52 -------
I think maybe Burton, in trying to help, has confused the issue here.

All my initial report was saying is that if you use an alias of a template type instead of the original type, then IFTI stops working.

Here's the example again:

This *works*:

struct Base(T) {}
void foo(T)(Base!(T) x) {}
main() {
   Base!(float) b;
   foo(b); OK
}

But just by making an alias of the Base type, it no longer works:

struct Base(T) {}
alias Base Alias;
void foo(T)(Alias!(T) x) {}
main() {
   Base!(float) b;
   foo(b); // fails!
}

Alias is supposed to be the exact same type as Base, but yet template matching fails when that's the parameter.

I think this is a different issue from the one Burton tacked on, and from the one you said was invalid.


-- 

February 22, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1454





------- Comment #7 from bugzilla@digitalmars.com  2008-02-22 16:18 -------
You're right, that is a different issue. I'll fix it.


-- 

March 07, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1454


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED




------- Comment #8 from bugzilla@digitalmars.com  2008-03-07 00:20 -------
Fixed dmd 1.028 and 2.012


--