Error in assignment to 'this' inside constructor

evilrat evilrat666 at gmail.com
Sun May 12 03:38:40 PDT 2013


On Sunday, 12 May 2013 at 07:51:39 UTC, TommiT wrote:
> On Sunday, 12 May 2013 at 03:32:44 UTC, evilrat wrote:
>> what? structs has value semantics, every time you assign a 
>> struct to variable it assign its copy.
>>
>> you also don't have to have constructor for structs, it 
>> initializes it fields in left-to-right order or so.
>>
>> [..]
>
> Yes, I know that. But I'm not trying to write a struct such as 
> 'Test' in my example above. 'Test' is just the simplest example 
> I could make in order to showcase the (assumed) compiler bug. 
> The struct that I *am* trying to make does indeed need a 
> constructor and it's a very complex one and I do need a way to 
> assign different compile-time-constant values of that struct 
> type over 'this' inside the constructor.
>
> Anyway, if no-one tells me otherwise, I'll just assume it's a 
> compiler bug and make a bug-report about it.

the problem with structs in your case is that this a value type, 
so may be you could use copy contructor?

struct Something {
// copy ctor
this(Something s) {}
}

now just imagine how do you change "this" for a variable(or 
simply variable itself) which tried to copy something over 
itself? the closest possible thing is a reference, and that 
behavior seems absolutely logically correct, otherwise if 
modifying "this" would be allowed that would be easy way to do 
lots of errors where you don't expect them.

but still if you think it's a bug fill a request or try also 
2.063 beta.


More information about the Digitalmars-d-learn mailing list