Le 29/11/09 00:36, Walter Bright a écrit :
And here it is (called opDispatch, Michel Fortin's suggestion):

http://www.dsource.org/projects/dmd/changeset?new=trunk%2f...@268&old=trunk%2f...@267


Seems interesting, but for now the error message when no opDispatch template can be instantiated looks confusing when trying to use a class with an opDispatch implemented, and making e.g. a typo error:

=============================================
module lib;
class Test
{
    string opDispatch(string name)()
    {
        static if (name == "foo")
            return "foo";
    }
}
=============================================
module main;
import lib;
import std.stdio;

void main()
{
    auto test = new Test;
    writeln(test.foo); // OK
    writeln(test.fooo); // Error
}
=============================================

Error is: """
lib.d(5): Error: function lib.Test.opDispatch!("fooo").opDispatch expected to return a value of type string lib.d(9): Error: template instance lib.Test.opDispatch!("fooo") error instantiating
"""

nicolas


Reply via email to