Compiler bug? (alias sth this; and std.signals)

eskimo jfanatiker at gmx.at
Thu Nov 15 01:38:27 PST 2012


On Thu, 2012-11-15 at 09:53 +0100, Joe wrote:
> On Wednesday, 14 November 2012 at 09:31:47 UTC, eskimo wrote:
> > But first it is copied to every generic function that might be 
> > called on
> > the way.
> 
> Ok, I guess it just doesn't do what I understood it to do (which 
> is too bad, but to be expected with a new language). In any case 
> you would appear to be correct, as
> 
> void main()
> {
> 	Foo f;
> 	Observer o = new Observer;
> 	f.prop.connect(&o.watch);
> 	f.prop = 7;
> 	writeln(f.prop.get);
> }
> 
> works. It just doesn't look like intended.

Well if signal had a proper postblit constructor your original way of
doing it would work. It is just not as efficient, but this is a price
you have to pay. The compiler has no way of knowing that you intended to
pass the contained int from the beginning, when you are actually passing
the containing struct.

But, considering that the alias this triggers only when you are issuing
an operation not supported by the struct itself, it is pretty reasonable
behaviour and everything else would be pretty surprising.

Best regards,

Robert




More information about the Digitalmars-d mailing list