Aliasing multiple delegates to the same name - very strange behaviour

Nicholas Wilson iamthewilsonator at hotmail.com
Sun Feb 25 04:47:47 UTC 2018


On Sunday, 25 February 2018 at 04:06:43 UTC, Meta wrote:
> I just filed this bug: 
> https://issues.dlang.org/show_bug.cgi?id=18520
>
> Not only does the following code compile and link successfully, 
> it prints 0 three times when ran:
>
> alias f = (int n) => 0;
> alias f = (char c) => 'a';
> alias f = (bool b) => false;
>
> void main()
> {
>     import std.stdio;
>     writeln(f(int.init));  //Prints 0
>     writeln(f(char.init)); //Prints 0
>     writeln(f(bool.init)); //Prints 0
> }
> [...]
> 4. Is there any different semantically or mechanically between 
> my first and second examples?

Type promotions to int maybe?
Have you tried casting them?

> void main()
> {
>     import std.stdio;
>     writeln(f(cast(int)int.init));
>     writeln(f(cast(char)char.init));
>     writeln(f(cast(bool)bool.init));
> }


More information about the Digitalmars-d mailing list