Thread overview
Can't assign to static array in ctor?
Apr 09, 2012
H. S. Teoh
Apr 09, 2012
bearophile
Apr 10, 2012
Daniel Murphy
April 09, 2012
What's the reason the following code doesn't compile?

	struct S {
		const(int)[4] data;
		this(const(int)[4] d) {
			data = d;	// this is line 4
		}
	}

	void main() {
		S s;
	}

Compiler error:

	test.d(4): Error: slice this.data[] is not mutable

Shouldn't the assignment be valid in the ctor?


T

-- 
MSDOS = MicroSoft's Denial Of Service
April 09, 2012
H. S. Teoh:

> 	struct S {
> 		const(int)[4] data;
> 		this(const(int)[4] d) {
> 			data = d;	// this is line 4
> 		}
> 	}
>
> 	void main() {
> 		S s;
> 	}

I think this used to work (do you have an older DMD to verify it?). So maybe this is regression.

Bye,
bearophile
April 10, 2012
"H. S. Teoh" <hsteoh@quickfur.ath.cx> wrote in message news:mailman.1550.1333997204.4860.digitalmars-d@puremagic.com...
> What's the reason the following code doesn't compile?
>
> struct S {
> const(int)[4] data;
> this(const(int)[4] d) {
> data = d; // this is line 4
> }
> }
>
> void main() {
> S s;
> }
>
> Compiler error:
>
> test.d(4): Error: slice this.data[] is not mutable
>
> Shouldn't the assignment be valid in the ctor?
>
>
> T

Static array assignments are converted to slice assignments waaay too early.