On 2013-04-25, 23:05, Ali Çehreli wrote:

This question has first appeared on D.learn:

   http://forum.dlang.org/post/vlosugoeuobjrdfae...@forum.dlang.org

A simple program:

import std.stdio;

void foo(bool b)
{
     writeln("bool");
}

void foo(long l)
{
     writeln("long");
}

void main()
{
     foo(1);
     foo(2);
}

The program calls two separate foo() overloads for 1 and 2:

bool
long

According to the language spec, both overloads match the int argument by "implicit conversion" as described under "Function Overloading" here:

   http://dlang.org/function.html

Then, the overload must be resolved by partial ordering: "If two or more functions have the same match level, then partial ordering is used to try to find the best match. Partial ordering finds the most specialized function."

Is bool more specialized than long or is this a bug? Intuitively, both should match the 'long' overload. It feels like there should at least be ambiguity.

For what it's worth, this is ambiguous in C++.


--
Simen

Reply via email to