On Sunday, 29 June 2014 at 08:52:36 UTC, Uranuz wrote:
import std.stdio;

string getByName(string name)
{
        return "smth";
}

template getByName(string name)
{
        enum getByName = .getByName(name);
}


void main()
{
        writeln(getByName!("name"));
}

Thanks a lot! Very interesting. Do you see any reasoning why this happens?

I think it has to do with variable shadowing. The lookup rules for enums are the same as for variables. Since the getByName enum is declared inside the template scope it takes precedence over the function in the outer scope, even when initializing the enum.

I'm not sure though, hopefully someone a bit more knowledgeable than me comes along to clarify.

Prepending a dot makes the lookup happen in global scope.

Reply via email to