Poll: what should this program do?

monkyyy crazymonkyyy at gmail.com
Wed Mar 19 04:34:11 UTC 2025


On Wednesday, 19 March 2025 at 03:40:28 UTC, Paul Backus wrote:
> Here's a weird little program that came up in a recent Discord 
> discussion:
>
>     template fun(T)
>     {
>         string fun(T) => fun("hi");
>         string fun(string) => "inner";
>     }
>     string fun(string) => "outer";
>
>     void main()
>     {
>         import std.stdio;
>         writeln(fun(123));
>     }
>
>
> **What SHOULD this program do?**
>
> 1. Print "inner".
> 2. Print "outer".
> 3. It shouldn't compile.
>
> **What do you think it ACTUALLY does?**
>
> 1. Print "inner".
> 2. Print "outer".
> 3. It doesn't compile.

It should print outer and does print outer
you didnt actually introduce ambiguity

```d
template fun(alias T)
{
     string fun(T) => fun("hi");
     string fun(string) => "inner";
}
string fun(string) => "outer";

void main()
{
     import std.stdio;
     writeln(fun(123));
}
```

fails


More information about the Digitalmars-d mailing list