Properties: a.b.c = 3

Steven Schveighoffer schveiguy at yahoo.com
Wed Jul 29 11:23:03 PDT 2009


On Wed, 29 Jul 2009 14:08:18 -0400, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> Steven Schveighoffer wrote:
>> It would be nice if the compiler could help by simply rejecting what it  
>> can reject (assignment to rvalues), but other than that, there's not  
>> much that can be done.
>>  This can be detected in simple cases, but in the case where the end  
>> point is a function, it will be difficult or impossible.
>
> I think it is eminently possible, but we must figure a solution that  
> doesn't complicate the language all too much.

Here is a struct, defined in a .di file:

struct S
{
   private int _c;
   int c();
   void c(int n);
}

struct S2
{
   S b();
}

Now, in your main file you have:

void main()
{
   S2 a;
   a.b.c = 3;
}

How in the world is the compiler supposed to know whether to allow this or  
not?  What if the actual code for S looks like this:

struct S
{
   private int _c;
   int c() {return *(cast(int*)_c);}
   void c(int n) {*(cast(int*)_c) = n;}
}

Shouldn't this be allowed?

-Steve



More information about the Digitalmars-d mailing list