1 matches bool, 2 matches long

Maxim Fomin maxim at maxim-fomin.ru
Thu Apr 25 18:44:13 PDT 2013


On Thursday, 25 April 2013 at 21:05:43 UTC, Ali Çehreli wrote:
> This question has first appeared on D.learn:
>
> ...
>
> 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

Looks like value range propagation bug because 1 is integer 
literal and should be converted to long. There is no way for 1 to 
be converted to bool here (from TDPL long is below int and it is 
the shortest way, value range propagation can work upwards, but 
the path would be longer).


More information about the Digitalmars-d mailing list