www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14237] New: Poor diagnostic when declaring a init() class


          Issue ID: 14237
           Summary: Poor diagnostic when declaring a init() class member
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: heartcollector.87 gmail.com

This sample program will create a really difficult-to-understand error message.

import std.container;

class MyClass
    void init() {};

private Array!MyClass temp;

void main() {}

/opt/compilers/dmd2/include/std/container.d(2562): Error: template
std.algorithm.initializeAll cannot deduce function from argument types
!()(MyClass[]), candidates are:
std.algorithm.initializeAll(Range)(Range range) if (isInputRange!Range &&
hasLvalueElements!Range && hasAssignableElements!Range)
std.algorithm.initializeAll(Range)(Range range) if (is(Range == char[]) ||
is(Range == wchar[])) /opt/compilers/dmd2/include/std/container.d(3391): Error:
template std.algorithm.copy cannot deduce function from argument types
!()(Range, Range), candidates are:
/opt/compilers/dmd2/include/std/algorithm.d(7497): std.algorithm.copy(Range1,
Range2)(Range1 source, Range2 target) if (isInputRange!Range1 &&
isOutputRange!(Range2, ElementType!Range1))

DMD does not complain if a user declares a init() member function for a class,
even if init() is a property defined for every Type. This can cause really ugly
errors as the one displayed above. Usually trying to define a property and a
function with the same name results in a much nicer error.

Mar 02 2015