Comment #0 by john.loughran.colvin — 2018-08-14T09:11:34Z
struct A
{
alias a = int;
alias b = this.a;
// Deprecation: Using this as a type is deprecated. Use typeof(this) instead
}
A a;
alias b = a.a; // OK
This seems inconsistent.
Comment #1 by ag0aep6g — 2018-08-14T11:26:58Z
In the first case, there is no `this` object, so DMD interprets it to mean the type of `this`. That's been deprecated.
In the second case, there is an `a` object. The alias is still the same as `typeof(a).a`, but that's ok. Making the alias has not been deprecated. The deprecation is about using `this` where there is no object `this`.
Similarly, you can still use `alias b = this.a;` inside a method:
----
struct A
{
alias a = int;
void m()
{
alias b = this.a; /* no deprecation */
}
}
----
I'm closing this as invalid. As usual, feel free to reopen if I missed something.
Comment #2 by john.loughran.colvin — 2018-08-14T12:35:22Z
How about this, which the compiler is OK with:
struct A
{
alias a = int;
}
struct B
{
A a;
alias b = a.a;
}
I don't understand the logic that says we can't directly access compile-time members of `this` at struct scope but we can access compile-time members of member variables.
Comment #3 by ag0aep6g — 2018-08-14T12:53:42Z
(In reply to John Colvin from comment #2)
> How about this, which the compiler is OK with:
>
> struct A
> {
> alias a = int;
> }
>
> struct B
> {
> A a;
> alias b = a.a;
> }
>
> I don't understand the logic that says we can't directly access compile-time
> members of `this` at struct scope but we can access compile-time members of
> member variables.
I think you're right. If we can use `a` that way, we should be able to use `this`, too. There's also this:
----
struct A
{
enum a = 1;
enum b = this.a; /* no deprecation */
}
----
So DMD doesn't reject all cases of `this`. If the enum is acceptable, the alias in the original snippet should be acceptable, too.
Comment #4 by razvan.nitu1305 — 2018-11-05T14:42:04Z
I think that the real bug is that in the enum case the deprecation should be triggered.
Comment #5 by slavo5150 — 2019-07-27T01:55:36Z
> I think that the real bug is that in the enum case the deprecation should be triggered.
I agree.
Comment #6 by robert.schadek — 2024-12-13T19:00:19Z