www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - opDispatch with template parameter and property syntax doesn't work

reply Jacob Carlborg <doob me.com> writes:
The following doesn't work, is it a known issue or should I report it.

class C
{
	void opDispatch (string str, T) (T t) {}
}

class D
{
	void opDispatch (string str) (int t) {}
}

C c = new C;
c.foo = 3; // doesn't work
c.foo(3); // works

D d = new D;
d.foo = 3; // works
Jan 12 2010
next sibling parent Eldar Insafutdinov <e.insafutdinov gmail.com> writes:
Jacob Carlborg Wrote:

 The following doesn't work, is it a known issue or should I report it.
 
 class C
 {
 	void opDispatch (string str, T) (T t) {}
 }
 
 class D
 {
 	void opDispatch (string str) (int t) {}
 }
 
 C c = new C;
 c.foo = 3; // doesn't work
 c.foo(3); // works
 
 D d = new D;
 d.foo = 3; // works

If you watched the presentation by Anders Hejlsberg which was posted here recently, they have different methods to implement for methods and property look up for their dynamic type system. I would not want to have them mixed. Maybe something like opProperty?
Jan 12 2010
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Tue, 12 Jan 2010 14:04:44 -0500, Jacob Carlborg <doob me.com> wrote:

 The following doesn't work, is it a known issue or should I report it.

 class C
 {
 	void opDispatch (string str, T) (T t) {}
 }

 class D
 {
 	void opDispatch (string str) (int t) {}
 }

 C c = new C;
 c.foo = 3; // doesn't work
 c.foo(3); // works

 D d = new D;
 d.foo = 3; // works

I would expect that in the future you must annotate your opDispatch with property to get the correct behavior. If at that point, C's opDispatch doesn't work like a property, I would report a bug. The property behavior is very much in flux right now. But I wouldn't expect IFTI to work on a property syntax like that unless the function is actually labeled with property. -Steve
Jan 12 2010