[Issue 24781] New: alias this on inner structs have wrong behaviour
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Sep 23 16:51:31 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24781
Issue ID: 24781
Summary: alias this on inner structs have wrong behaviour
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: contact at lsferreira.net
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`.
--
More information about the Digitalmars-d-bugs
mailing list