[Issue 11346] [2.064 beta] field initializing not allowed in loops or after labels
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Oct 24 17:24:38 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=11346
--- Comment #1 from Kenji Hara <k.hara.pg at gmail.com> 2013-10-24 17:24:38 PDT ---
(In reply to comment #0)
> Code:
> ----
> import std.stdio;
>
> struct Test {
> public:
> const int[] test;
>
> this(int i) {
> for (size_t j = 0; j < 4; ++j) {
> this.test ~= i + j;
> }
> }
> }
>
> void main() {
> Test t = Test(42);
> }
> ----
>
> Error: field test initializing not allowed in loops or after labels
>
> WTF?
It's intended behavior change introduced by fixing bug 9665.
Possible code fix is:
this(int i) {
int[] tmp;
for (size_t j = 0; j < 4; ++j) {
tmp ~= i + j;
}
this.test = tmp; // initialize non-mutable field only once
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list