Thread overview | |||||
---|---|---|---|---|---|
|
April 09, 2012 Can't assign to static array in ctor? | ||||
---|---|---|---|---|
| ||||
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 Re: Can't assign to static array in ctor? | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | 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 Re: Can't assign to static array in ctor? | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | "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. |
Copyright © 1999-2021 by the D Language Foundation