On Tuesday, 20 February 2018 at 11:27:23 UTC, Alex wrote:
There is a related ticket,
https://issues.dlang.org/show_bug.cgi?id=6434
However, not exactly facing this question.

Should that ticket be marked as resolved? The issue is for alias this to be considered before opDispatch but there were no arguments after giving reasons for that being a bad idea. And opDispatch is considered before (and disables alias this) now it seems?


It seems, that currently opDispatch replaces alias this... (?)
Nevertheless, not only T is the wrapped type, but also A with the alias. What to do, if both members have a property with the same name? And why?

Good question, should it be dealt with in the same way as this is dealt with?

struct S {
    void f() {writeln("S");}
}
struct A {
    S s; alias s this;
    void f() {writeln("A");}
}
A().f; // prints "A"

However, the above behavior seems dangerous maybe and could lead to silent bugs. I'm thinking if A.f was not defined, then A().f would print "S". But then someone comes along and defines an A.f and the user of A now gets different functionality without even knowing about it. Hrm.. one is not sure how one feels :p

But how about if they do not have the same name? Currently AliasThis says: "If the member is a class or struct, undefined lookups will be forwarded to the AliasThis member."

So opDispatch, even though it's constrained, is not considered undefined if it doesn't pass. In those cases should it not be forwarded to the alias this? If not, then why does a constrained function not qualify as being undefined if the constraint doesn't pass?

Consider:

struct A {
    void defined() {}
}

struct B {
    void opDispatch(string name)() if (name == "defined") {}
}

void main() {
        A().defined; // ok
        B().defined; // ok
        A().undefined;
        B().undefined;
}

Errors are:
* Error: no property 'undefined' for type 'A', did you mean 'defined'?
* Error: no property 'undefined' for type 'B'

If you then define a struct S that contains a function named "undefined" and add a "S s; alias s this;" inside A and B, you get:

* Error: no property 'undefined' for type 'B'

But not for A. Shouldn't the behavior here be consistent? Or why not?

Churr,
- Ali


Reply via email to