www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - opDispatch bug?

reply "Zhenya" <zheny list.ru> writes:
Hi!
Is it a bug?

class Foo
{
	int m_bar;
	char m_gun;
	 property auto ref opDispatch(string s)()
	{
		return mixin("m_"~s);	
	}
	this(int i,char c)
	{
		bar = i;//Error: undefined identifier bar, did you mean 
variable m_bar?
		this.gun = c;
	}
}
Dec 15 2012
parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 12/15/2012 10:01 AM, Zhenya wrote:
 Hi!
 Is it a bug?

 class Foo
 {
 int m_bar;
 char m_gun;
  property auto ref opDispatch(string s)()
 {
 return mixin("m_"~s);
 }
 this(int i,char c)
 {
 bar = i;//Error: undefined identifier bar, did you mean variable m_bar?
this.bar = i; Because when it is simply bar, there is no indication that we are talking about a member of this type. So, opDispatch() is not considered. It could be the other way around as well, but personally I like the current behaviour. Otherwise any type would go to opDispatch.
 this.gun = c;
 }
 }
Ali
Dec 15 2012
parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 12/15/2012 10:07 AM, Ali Çehreli wrote:

 Otherwise any type would go to opDispatch.
Wow. I made a typo in typo. :) That should be: Otherwise any _typo_ would go to opDispatch. Ali
Dec 15 2012
parent "Zhenya" <zheny list.ru> writes:
On Saturday, 15 December 2012 at 18:09:00 UTC, Ali Çehreli wrote:
 On 12/15/2012 10:07 AM, Ali Çehreli wrote:

 Otherwise any type would go to opDispatch.
Wow. I made a typo in typo. :) That should be: Otherwise any _typo_ would go to opDispatch. Ali
It's pretty reasonable,thank you.
Dec 15 2012