On Friday, 10 October 2014 at 22:18:36 UTC, Timon Gehr wrote:
On 10/11/2014 12:07 AM, IgorStepanov wrote:
On Friday, 10 October 2014 at 21:25:17 UTC, Walter Bright
wrote:
If 'a' and 'b' both contain overloads for function foo, then
it should
behave like imports do (which is a bit complex).
Hmm. Now it works as I wrote it DIP pseudo-code:
The pseudo-code doesn't actually specify that the arguments the
identifier is being called with are considered at all.
struct A
{
void foo(string);
void foo(int);
}
struct B
{
void foo(double);
}
struct C
{
A a;
B b;
alias a this;
alias b this;
}
C.foo("test"); //found only one acceptable foo: C.a.foo(string)
C.foo(5); //1. Check a: found C.a.foo(int);
//2. Check b: found C.b.foo(double);
//3. Raise error: C.a.foo(int) vs
C.b.foo(double) conflict
C.foo(5.0); //found only one acceptable foo: C.b.foo(double)
Is it Ok?
...
That is the right behaviour. What happens in this case:
struct A{
void foo(int);
void foo(double);
}
struct B
void foo(string);
}
... // (struct C and calls as yours)
C.foo("test"); //Ok, C.b.foo(string);
C.foo(5); //Ok, C.a.foo(int);
C.foo(5.0); //Ok, C.a.foo(double);
Compiler simply tries to forward c.foo(ARG) -> c.a.foo(ARG) and
c.b.foo(ARG). If only one is correct, compiler will accept it. If
both is correct, compiler will raise an error.