www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15640] New: type inference in variadic array params not

https://issues.dlang.org/show_bug.cgi?id=15640

          Issue ID: 15640
           Summary: type inference in variadic array params not working
                    for classes
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: schuetzm gmx.net

void test(T)(T[] args...) {
        import std.stdio;
        writeln(T.stringof);
    }

    class A     { }
    class B : A { }
    class C : A { }

    void main()
    {
        test(1,2,3);    // int
        test(4,5,6.9);  // double
        test(new B(), new C());
    }

=> template xx.test cannot deduce function from argument types !()(B, C)

IMO `T` should be inferred as `A`. Note that the common type is already chosen
for mixed numerical types; it's an arbitrary restriction for it not to work
with classes.

--
Feb 02 2016