[Issue 16222] New: template failed to infer/coerce types for instantiation
    via Digitalmars-d-bugs 
    digitalmars-d-bugs at puremagic.com
       
    Thu Jun 30 04:31:21 PDT 2016
    
    
  
https://issues.dlang.org/show_bug.cgi?id=16222
          Issue ID: 16222
           Summary: template failed to infer/coerce types for
                    instantiation
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: ketmar at 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
'typeof(null)'"
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.
--
    
    
More information about the Digitalmars-d-bugs
mailing list