www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - property method needs ()

reply "Andre" <andre s-e-a-p.de> writes:
Hi,

in following example the  property method needs the ()
otherwise compiler error  for row 24 is thrown.
I cannot judge, whether the compiler behaves correct or not.

Kind regards
André

---

alias fnError = void delegate(string s);

interface IfSession
{
	 property fnError addError();
}

class Session: IfSession
{
	private fnError _addError;
	
	 property fnError addError()
	{
		return _addError;
	}
}

void main()
{
	auto session = new Session();
	session._addError = delegate(s){};
	
	session.addError()("test"); // Works
	session.addError("test"); // Does not work
}
Nov 23 2014
parent reply ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Mon, 24 Nov 2014 06:56:08 +0000
Andre via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:

 Hi,
=20
 in following example the  property method needs the ()
 otherwise compiler error  for row 24 is thrown.
 I cannot judge, whether the compiler behaves correct or not.
=20
 Kind regards
 Andr=C3=A9
=20
 ---
=20
 alias fnError =3D void delegate(string s);
=20
 interface IfSession
 {
 	 property fnError addError();
 }
=20
 class Session: IfSession
 {
 	private fnError _addError;
 =09
 	 property fnError addError()
 	{
 		return _addError;
 	}
 }
=20
 void main()
 {
 	auto session =3D new Session();
 	session._addError =3D delegate(s){};
 =09
 	session.addError()("test"); // Works
 	session.addError("test"); // Does not work
 }
a known thing. not sure if this is a known *bug* (seems that almost nobody cares). compiler is obviously wrong here (and i believe that it's wrong to accept `()` for properties at all), but i don't know if this will ever be fixed.
Nov 24 2014
parent reply "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
On Monday, 24 November 2014 at 08:35:08 UTC, ketmar via 
Digitalmars-d-learn wrote:
 On Mon, 24 Nov 2014 06:56:08 +0000
 Andre via Digitalmars-d-learn 
 <digitalmars-d-learn puremagic.com> wrote:

 Hi,
 
 in following example the  property method needs the ()
 otherwise compiler error  for row 24 is thrown.
 I cannot judge, whether the compiler behaves correct or not.
 
 Kind regards
 André
 
 ---
 
 alias fnError = void delegate(string s);
 
 interface IfSession
 {
 	 property fnError addError();
 }
 
 class Session: IfSession
 {
 	private fnError _addError;
 	
 	 property fnError addError()
 	{
 		return _addError;
 	}
 }
 
 void main()
 {
 	auto session = new Session();
 	session._addError = delegate(s){};
 	
 	session.addError()("test"); // Works
 	session.addError("test"); // Does not work
 }
a known thing. not sure if this is a known *bug* (seems that almost nobody cares). compiler is obviously wrong here (and i believe that it's wrong to accept `()` for properties at all), but i don't know if this will ever be fixed.
There's hope that this will get fixed in the near future: https://github.com/D-Programming-Language/dmd/pull/2305
Nov 24 2014
parent "Andre" <andre s-e-a-p.de> writes:
Thanks a lot for the info.

Kind regards
André

On Monday, 24 November 2014 at 09:26:16 UTC, Marc Schütz wrote:
 On Monday, 24 November 2014 at 08:35:08 UTC, ketmar via 
 Digitalmars-d-learn wrote:
 a known thing. not sure if this is a known *bug* (seems that 
 almost
 nobody cares). compiler is obviously wrong here (and i believe 
 that
 it's wrong to accept `()` for properties at all), but i don't 
 know if
 this will ever be fixed.
There's hope that this will get fixed in the near future: https://github.com/D-Programming-Language/dmd/pull/2305
Nov 24 2014