Jump to page: 1 2
Thread overview
[Issue 19060] [REG2.081] Incorrect "Using this as a type is deprecated" error
Jul 04, 2018
Richard Cattermole
Jul 04, 2018
Richard Cattermole
Jul 04, 2018
Richard Cattermole
Jul 04, 2018
ag0aep6g
Jul 05, 2018
RazvanN
Nov 05, 2018
RazvanN
Nov 05, 2018
ag0aep6g
Nov 06, 2018
RazvanN
Nov 06, 2018
ag0aep6g
Dec 18, 2019
Walter Bright
July 04, 2018
https://issues.dlang.org/show_bug.cgi?id=19060

johanengelen@weka.io changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |industry

--
July 04, 2018
https://issues.dlang.org/show_bug.cgi?id=19060

Richard Cattermole <alphaglosined@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |alphaglosined@gmail.com
         Resolution|---                         |INVALID

--
July 04, 2018
https://issues.dlang.org/show_bug.cgi?id=19060

--- Comment #1 from Richard Cattermole <alphaglosined@gmail.com> ---
This was changed on purpose.

https://dlang.org/changelog/2.081.0.html#deprecate_this_super_as_types

--
July 04, 2018
https://issues.dlang.org/show_bug.cgi?id=19060

Richard Cattermole <alphaglosined@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---

--- Comment #2 from Richard Cattermole <alphaglosined@gmail.com> ---
Okay looks like I was wrong.

Removing the class it would be equivalent at the module level to:

---
module self;

bool x;
template Foo() {
        alias y = self.x;
}
alias Bar = Foo!();
---

--
July 04, 2018
https://issues.dlang.org/show_bug.cgi?id=19060

ag0aep6g <ag0aep6g@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ag0aep6g@gmail.com

--- Comment #3 from ag0aep6g <ag0aep6g@gmail.com> ---
As far as I can see, the deprecation is correct. You can't get an alias of an instance field. The alias was to `S.x` the whole time. You're just being forced to spell it out now.

--
July 05, 2018
https://issues.dlang.org/show_bug.cgi?id=19060

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305@gmail.com

--- Comment #4 from RazvanN <razvan.nitu1305@gmail.com> ---
Indeed, this is not a regression, it is intended behavior.

--
July 05, 2018
https://issues.dlang.org/show_bug.cgi?id=19060

--- Comment #5 from johanengelen@weka.io ---
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;
    }
}
```

--
November 05, 2018
https://issues.dlang.org/show_bug.cgi?id=19060

--- Comment #6 from RazvanN <razvan.nitu1305@gmail.com> ---
(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. 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.

I suggest to close this as invalid.

--
November 05, 2018
https://issues.dlang.org/show_bug.cgi?id=19060

--- Comment #7 from ag0aep6g <ag0aep6g@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;`.

--
November 06, 2018
https://issues.dlang.org/show_bug.cgi?id=19060

--- Comment #8 from RazvanN <razvan.nitu1305@gmail.com> ---
(In reply to ag0aep6g from comment #7)
> (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;`.

This is surprising, indeed, and I would say that this is a bug. Why would it do that?

--
« First   ‹ Prev
1 2