Is @property implementable?

Jonathan M Davis jmdavisProg at gmx.com
Thu Mar 3 00:34:22 PST 2011


On Wednesday 02 March 2011 23:21:21 Bekenn wrote:
> On 3/2/2011 9:21 PM, Jonathan M Davis wrote:
> > Well, it wouldn't be universal then.
> 
> Agreed, and really, I don't have a problem with it being universal.  I'd
> prefer an annotation, but it's not that big a deal.  I'm just thinking
> of the following situation:
> 
> 
> 
> lib1.di:
> 	class Lib1Class
> 	{
> 		...
> 		version (2)
> 		{
> 			void bar();
> 		}
> 	}
> 
> lib2.di:
> 	import lib1;
> 	void bar(Lib1Class l1c);
> 
> main.d:
> 	import lib1;
> 	import lib2;
> 
> 	void main()
> 	{
> 		Lib1Class foo;
> 		foo.bar();
> 	}
> 
> 
> Through no fault of the caller or of lib2, foo.bar() goes from one
> completely valid meaning to another when lib1 is versioned.  Lib1 and
> lib2 could be from different authors, so lib1's author had no idea he'd
> just hijacked a function call.
> 
> With an annotation, the compiler could at least spit out a warning for
> lib2.di.  (I would be absolutely opposed to a warning for line 7 of
> main; that should be an unambiguous method call in version 2.)
> 
> Anyway, I'm just thinking out loud (erm, in text); I'm sure this has all
> been debated already.

No, not all of the details have been ironed out. It's not even sure that it's 
ever going to be implemented. However, the whole point of the feature of 
universal function call syntax is to have a universal syntax for calling 
functions. It's supposed to work for all types. So, annotations defeat the 
purpose.

It has been suggested that UFCS not affect structs or classes (which would fix 
this case). But even if UFCS _did_ affect structs and classes, in this particular 
case, if both functions existed, it would either result in an error due to the 
ambiguity, or it would simply call the member function. Regardless, with the 
current state of D, if the functions in imported libraries change, then the 
functions being called could change. There's no way around that. It's just that 
D has rules specifically designed to limit the possibility of function hijacking.

If UFCS _is_ ever implemented, then there _are_ definitely some issues which will 
have be ironed out, but you're not going to end up with annotations regardless. 
Arrays don't work that way and annotations would defeat the purpose of the 
feature. However, it's issues like this which could lead to UFCS never being 
implemented even if Walter definitely decides to take a stab at it.

- Jonathan M Davis


More information about the Digitalmars-d mailing list