digitalmars.D.learn - Bug? aliasing member of instance
- Nick Sabalausky (15/16) Oct 22 2011 Is this a compiler bug?
- Timon Gehr (14/30) Oct 22 2011 alias has never worked for instance members, even if they are accessible...
- Nick Sabalausky (3/5) Oct 22 2011 Any idea if it's supposed to work?
- Timon Gehr (5/11) Oct 22 2011 I do not know. But if it was not supposed to work, the error message
- Nick Sabalausky (5/18) Oct 22 2011 I've filled a report. If it's invalid it can be closed or changed to "ba...
- Steven Schveighoffer (13/29) Oct 24 2011 alias works on *symbols* not data.
Is this a compiler bug? -------------------------------- struct Foo { int a; } Foo foo; alias foo.a b; void main() { b = 5; // <-- Error } --------------------------------dmd test.dtest.d(11): Error: need 'this' to access member a I did this on DMD 2.055
Oct 22 2011
On 10/22/2011 09:28 AM, Nick Sabalausky wrote:Is this a compiler bug? -------------------------------- struct Foo { int a; } Foo foo; alias foo.a b; void main() { b = 5; //<-- Error } --------------------------------alias has never worked for instance members, even if they are accessible at compile time. The workaround for your example could be this: ref property b(){return foo.a;} // instead of alias foo.a b; Another case where we currently have this meaningless error message: struct Foo{ int a; int foo(int res=a){return res;} } void main(){ Foo x; x.foo(); } I think that should work.dmd test.dtest.d(11): Error: need 'this' to access member a I did this on DMD 2.055
Oct 22 2011
"Timon Gehr" <timon.gehr gmx.ch> wrote in message news:j7u9ld$i8t$1 digitalmars.com...alias has never worked for instance members, even if they are accessible at compile time.Any idea if it's supposed to work?
Oct 22 2011
On 10/22/2011 11:03 PM, Nick Sabalausky wrote:"Timon Gehr"<timon.gehr gmx.ch> wrote in message news:j7u9ld$i8t$1 digitalmars.com...I do not know. But if it was not supposed to work, the error message could certainly be improved. It is odd that the alias compiles fine but cannot be used later on. That fact maybe indicates that it is supposed to work.alias has never worked for instance members, even if they are accessible at compile time.Any idea if it's supposed to work?
Oct 22 2011
"Timon Gehr" <timon.gehr gmx.ch> wrote in message news:j7ve1p$2rds$1 digitalmars.com...On 10/22/2011 11:03 PM, Nick Sabalausky wrote:I've filled a report. If it's invalid it can be closed or changed to "bad error message": http://d.puremagic.com/issues/show_bug.cgi?id=6842"Timon Gehr"<timon.gehr gmx.ch> wrote in message news:j7u9ld$i8t$1 digitalmars.com...I do not know. But if it was not supposed to work, the error message could certainly be improved. It is odd that the alias compiles fine but cannot be used later on. That fact maybe indicates that it is supposed to work.alias has never worked for instance members, even if they are accessible at compile time.Any idea if it's supposed to work?
Oct 22 2011
On Sat, 22 Oct 2011 03:28:53 -0400, Nick Sabalausky <a a.a> wrote:Is this a compiler bug? -------------------------------- struct Foo { int a; } Foo foo; alias foo.a b; void main() { b = 5; // <-- Error } --------------------------------alias works on *symbols* not data. For example, if Foo has a function bar(), aliasing foo.bar is equivalent to aliasing Foo.bar. You are aliasing the *function* not the *delegate*. So naturally, it would make sense that aliasing foo.a is equivalent to aliasing Foo.a, or the symbol that accesses the member 'a' in an instance of 'Foo'. I would expect this may work: void main() { foo.b = 5; } -Stevedmd test.dtest.d(11): Error: need 'this' to access member a I did this on DMD 2.055
Oct 24 2011