Type inference and overloaded functions

Jonathan M Davis jmdavisProg at gmx.com
Tue Dec 10 00:26:22 PST 2013


On Tuesday, December 10, 2013 09:00:22 Namespace wrote:
> I use this implict converting to static arrays very often and if
> we deprecate it, we really need something to declare static array
> literals.

Implicit conversion isn't the problem. It's the fact that there are two 
possible matches, and it picks one over the other rather than requiring the 
programmer to indicate which one is correct (e.g. via casting). That's just 
going to lead to bugs. If there is no conflict, then the implicit conversion is 
fine. It's just that when there is a conflict that it's a problem.

We have similar problems with stuff like

void foo(bool b) {...}
void foo(long l) {...}

foo(1); //calls the bool overload

There was a huge thread on this a while back where almost no one other than 
Walter thought that this behavior was good, and it was clearly causing bugs 
(Walter argued that the solution was to just add an overload for int rather 
than fixing the conversion problem). IMHO, there should be no implicit 
conversion of literals when there's a conflict. It should result in an 
ambiguity error so that the programmer has the opportunity to indicate the 
correct overload.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list