www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16222] New: template failed to infer/coerce types for


          Issue ID: 16222
           Summary: template failed to infer/coerce types for
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ketmar ketmar.no-ip.org

consider the following code:

  auto test(T : const(char)[]) (T s) { return s.length; }
  void main () { assert(test(null) == 0); }

compiling this gives the following error: "no property 'length' for type

while i see why it complains, i think compiler should convert `null` to empty
slice here, as i clearly specified the type i want to accept. sure, i can
workaround this with explicit template constrain... but this is what i wanted
to avoid in the first place!

also, another bug with the same `test`:
  assert(test([]) == 0);

this time compiler says: "
template z01.test cannot deduce function from argument types !()(void[]),
candidates are..."

i think compiler should convert empty slice to the `immutable(char)[]` here.

Jun 30 2016