www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - "alias foo this" compiles when "foo" is not defined

reply Ary Borenszweig <ary esperanto.org.ar> writes:
Is is ok that this compiles without errors?

class Foo {
	alias errorProne this;
}
Jun 26 2009
parent reply Jarrett Billingsley <jarrett.billingsley gmail.com> writes:
On Fri, Jun 26, 2009 at 5:54 PM, Ary Borenszweig<ary esperanto.org.ar> wrot=
e:
 Is is ok that this compiles without errors?

 class Foo {
 =A0 =A0 =A0 =A0alias errorProne this;
 }
If I had to guess, it's only OK because the compiler probably doesn't actually look for the aliased symbol until you actually try to access something from it. But that does seem .. wrong.
Jun 26 2009
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Jarrett Billingsley wrote:
 On Fri, Jun 26, 2009 at 5:54 PM, Ary Borenszweig<ary esperanto.org.ar> wrote:
 Is is ok that this compiles without errors?

 class Foo {
        alias errorProne this;
 }
Errors as expected on 1.042; compiles on 2.029.
 If I had to guess, it's only OK because the compiler probably doesn't
 actually look for the aliased symbol until you actually try to access
 something from it.  But that does seem .. wrong.
It is wrong. Since this isn't in a template, the compiler should perform semantic analysis on it in any case, and thus report an error. But the really strange thing is that it doesn't complain about the attempt to redefine 'this', which is a keyword. This ought to be in Bugzilla if it isn't already and you can't find anything in the spec that gives this form a meaning of its own. Strangely, if I change 'this' to 'that', I get the expected errorprone.d(2): Error: identifier 'errorProne' is not defined Stewart.
Jun 26 2009
parent Ary Borenszweig <ary esperanto.org.ar> writes:
Stewart Gordon escribió:
 Jarrett Billingsley wrote:
 On Fri, Jun 26, 2009 at 5:54 PM, Ary Borenszweig<ary esperanto.org.ar> 
 wrote:
 Is is ok that this compiles without errors?

 class Foo {
        alias errorProne this;
 }
Errors as expected on 1.042; compiles on 2.029.
 If I had to guess, it's only OK because the compiler probably doesn't
 actually look for the aliased symbol until you actually try to access
 something from it.  But that does seem .. wrong.
It is wrong. Since this isn't in a template, the compiler should perform semantic analysis on it in any case, and thus report an error. But the really strange thing is that it doesn't complain about the attempt to redefine 'this', which is a keyword.
It's called "alias this", that's not the problem: http://digitalmars.com/d/2.0/class.html#AliasThis I also think it should complain, because it makes no sense to just leave it there, unresolved.
Jun 26 2009