Poll: what should this program do?
Dukc
ajieskola at gmail.com
Wed Mar 19 12:30:23 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?**
>
Print "inner". Local symbol should hide the module-scope symbol,
and "inner" printer is local from where `fun("hi")` is called.
[The spec
says](https://dlang.org/spec/function.html#function-overloading)
that function overloading rules should only apply to functions in
the same scope.
>
> **What do you think it ACTUALLY does?**
>
No idea. What I think it ought to do would be my expectation but
the fact you posted this as a riddle hints it maybe doesn't work
like that.
More information about the Digitalmars-d
mailing list