1 matches bool, 2 matches long

Ali Çehreli acehreli at yahoo.com
Thu Apr 25 14:05:43 PDT 2013


This question has first appeared on D.learn:

   http://forum.dlang.org/post/vlosugoeuobjrdfaeegk@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.

Ali


More information about the Digitalmars-d mailing list