jcward / haxe-overload

Haxe macro library to support overloaded functions.
MIT License
18 stars 1 forks source link

Overloaded methods conflict with member methods #2

Closed jcward closed 6 years ago

jcward commented 6 years ago

Right now, any call to a <subject>.<field_name> (where field_name is any overloaded function name, defined in any tools class) will be checked for overload.

This blocks a member method of another type.

Two possible approaches to disabling the overload resolution:

1) Check the type at build time (some types may not be available) to see whether it defines the member. 2) Check the type at expression macro time to see whether it defines the member.

e.g.

using pkg.MyStringTools;

class Test
{
  public static function main()
  {
    trace("Haxe is great!");
    var s = "my string";

    // uses the first signature
    s = s.replace('my', 'our');
    trace(s); // our string

    // uses the second signature
    s = s.replace(~/str/, 'th');
    trace(s); // our thing

    // uses the third signature
    s = s.replace(~/[aeiou]/g, function(match) { return match.toUpperCase(); });
    trace(s); // OUr thIng

    var q = new Foo();
    q.replace();
  }
}

class Foo
{
  public function new() { }
  public function replace() {
    trace('Oh no, I got shadowed!');
  }
}