The following code:
struct Bar { @property bool isValid() { return true; } }
struct Club { @property bool isValid() { return false; } }
struct Foo
{
Bar bar;
alias bar this;
Foobar foobar;
struct Foobar
{
Club club;
alias club this;
bool humm() { return isValid(); }
}
static @property bool isValid() { assert(0); }
}
void main()
{
Foo foo;
imported!"std.stdio".writeln(foo.foobar.humm);
}
---
It is expected to print `false` but runs the `assert(0)`. `--preview=fixAliasThis` fixes the behaviour, but this is very very error prone and we found the bug at Weka that is not trivial to find.
I strongly suggest either making `--preview=fixAliasThis` the default and add deprecation messages on the cases where its affected by the new behaviour, or error these cases and ask to be explicit.
e.g.:
this should tell to use either `this.isValid` or `Foo.isValid`.
Comment #1 by razvan.nitu1305 — 2024-09-25T06:43:55Z
I fixed this bug in the past, but I remember that a fair amount of projects were broken by this change because they were relying on the existing behavior, that's why the preview was introduced (which had the effect that people continued using the broken version and relying on it more). Also, in this case it's really hard to issue deprecations since it's essentially silent change of code behavior. So we would either have to make the preview the default and deal with the breakage or continue as is. Of course, there's the dreaded alternative of making the preview the default in a new edition which would be the worse alternative since we will be stuck maintaining both behaviors.
Comment #2 by robert.schadek — 2024-12-13T19:37:32Z