[Issue 19060] [REG2.081] Incorrect "Using this as a type is deprecated" error

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Nov 5 16:56:31 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=19060

--- Comment #7 from ag0aep6g <ag0aep6g at gmail.com> ---
(In reply to RazvanN from comment #6)
> (In reply to johanengelen from comment #5)
> > OK, then this is still broken and should receive a deprecation message too:
> > 
> > ```
> > struct S {
> >     int a;
> >     bool x;
> >     public ref foo() {
> >         alias yoyo = this.x;
> >         return yoyo;
> >     }
> > }
> > ```
> 
> Actually, I don't think it should. Foo can only be called on an instance,
> therefore `this` does make sense in that context.

The alias is still to `S.x`. It still doesn't carry `this`.

For example, this might be surprising:

----
struct S {
    int x = 1;
    int foo(S other)
    {
        alias yoyo = other.x;
        return yoyo;
    }
}

void main()
{
    import std.stdio;
    auto s1 = S(1);
    auto s2 = S(2);
    writeln(s1.foo(s2)); /* prints "1" */
}
----

>From the alias declaration, one might expect to get `other.x`, i.e. 2.


> Imagine that you would
> define a local variable x, if you wouldn't be able to use `this` then the
> local would mask the member everywhere.

You can still write `alias x = S.x;`.

--


More information about the Digitalmars-d-bugs mailing list