[Issue 14237] New: Poor diagnostic when declaring a init() class member function.
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Mar 2 08:55:43 PST 2015
https://issues.dlang.org/show_bug.cgi?id=14237
Issue ID: 14237
Summary: Poor diagnostic when declaring a init() class member
function.
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: DMD
Assignee: nobody at puremagic.com
Reporter: heartcollector.87 at 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:
/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.
--
More information about the Digitalmars-d-bugs
mailing list