[Issue 15640] type inference in variadic array params not working for classes

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Oct 31 13:50:24 UTC 2022


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

RazvanN <razvan.nitu1305 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305 at gmail.com
         Resolution|---                         |WONTFIX

--- Comment #3 from RazvanN <razvan.nitu1305 at gmail.com> ---
Generally, the compiler tries to find the common type between the arguments,
however, the common type is chosen to be one of the types of the arguments.
Having the compiler infer the common type in the general case will add more
complexity to the compiler. However, for your use case you can just use
template variadic parameters:

```
void test(A...)(A a)
{
        import std.stdio;
        writeln(A.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());
}
```

This works.

So this is not a bug in the compiler, it could be seen at most as an
enhancement request, however, this does not buy us anything since we already
have syntax that takes care of the case.

--


More information about the Digitalmars-d-bugs mailing list