www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13283] New: dmd fails to generate ambiguous overload error


          Issue ID: 13283
           Summary: dmd fails to generate ambiguous overload error
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: vlevenfeld gmail.com

I have a generic Vector struct that is constructed by helper 
functions that deduce the length and element type and forward the 
arguments to the appropriate constructor. Almost all of them had 
a constraint on them that required the length of the vector the 
be at least 2, but the Vector struct itself had no such 
constraint, and one of the helper functions was missing it as 

When I added the constraint to either the Vector struct or the 
helper function (I've since added them to both) then everything 
links fine. It looks like what was happening was that a "fill 
constructor helper function" (intended use: vector!4 (x) => 
vector (x, x, x, x)) was routing to a "variadic constructor 
helper function" (vector (args) => vector!(args.length)(args)) 
that attempted to generate a 1-element vector and somewhere along 
the way - linker error.

There are the mangled names that the linker could not resolve 
references to:



the second of which demangles to this:

pure nothrow ref  safe evx.vectors.Vector!(1uL, double).Vector 
evx.vectors.Vector!(1uL, double).Vector.__ctor(double)

So, there's my one-element vector constructor, which is likely 
having a hard time with the following overloads:

    this (Elements...)(Elements elements)
    if (Elements.length == length)
        foreach (i, element; elements)
            components[i] = element;
    this (Element element)
        components[] = element;

So, while the mistake was mine, this should be an ambiguous 
overload error at compile-time, instead of a linker error.

Aug 11 2014