dmd/compiler/test/fail_compilation/alias_instance_member.d
Nick Treleaven 4a5c56d0f7 [next edition] Error when aliasing a method of a variable
https://dlang.org/spec/legacy#alias-instance-member

Also only error when the member actually needs `this`.
Show kind and name of member in error message.
2024-08-27 01:51:33 +02:00

29 lines
542 B
D

/*
TEST_OUTPUT:
---
fail_compilation/alias_instance_member.d(18): Error: cannot alias variable member `v` of variable `that`
fail_compilation/alias_instance_member.d(18): Use `typeof(that)` instead to preserve behaviour
---
*/
@__edition_latest_do_not_use
module aim;
struct Foo
{
int v;
void test(Foo that) const
{
alias a = this.v; // OK
alias b = that.v;
assert(&a is &b);
alias b2 = typeof(that).v; // OK
}
}
void main()
{
Foo a = Foo(1);
Foo b = Foo(2);
a.test(b);
}