Comment #0 by heartcollector.87 — 2015-03-02T16:55:43Z
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: /opt/compilers/dmd2/include/std/algorithm.d(1266): std.algorithm.initializeAll(Range)(Range range) if (isInputRange!Range && hasLvalueElements!Range && hasAssignableElements!Range) /opt/compilers/dmd2/include/std/algorithm.d(1294): 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.
Comment #1 by hsteoh — 2015-03-02T17:55:08Z
The compiler should reject attempts to define a member named 'init', because it conflicts with the special meaning of .init in the language.