Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix Issue 8783 - ref foreach update of const fixed size arrays in con…

…structor
  • Loading branch information...
commit a0da328e8d4cbdca1f9c983689b637c02d62f0b3 1 parent ee695eb
@9rnsr 9rnsr authored
View
9 src/declaration.c
@@ -138,8 +138,13 @@ int Declaration::checkModify(Loc loc, Scope *sc, Type *t)
if ((sc->flags & SCOPEcontract) && isResult())
error(loc, "cannot modify result '%s' in contract", toChars());
- if (isCtorinit() && !t->isMutable() ||
- (storage_class & STCnodefaultctor))
+ if (isCtorinit() && !t->isMutable())
+ {
+ if ((storage_class & (STCforeach | STCref)) == (STCforeach | STCref))
+ return TRUE;
+ return modifyFieldVar(loc, sc, isVarDeclaration(), NULL);
+ }
+ else if (storage_class & STCnodefaultctor)
{ // It's only modifiable if inside the right constructor
return modifyFieldVar(loc, sc, isVarDeclaration(), NULL);
}
View
4 src/statement.c
@@ -1812,7 +1812,9 @@ Statement *ForeachStatement::semantic(Scope *sc)
{
/* Reference to immutable data should be marked as const
*/
- if (!tn->isMutable())
+ if (aggr->checkCtorInit(sc))
+ var->storage_class |= STCctorinit;
+ else if (!tn->isMutable())
var->storage_class |= STCconst;
Type *t = tab->nextOf();
View
18 test/runnable/assignable.d
@@ -1121,6 +1121,24 @@ void test6336()
}
/***************************************************/
+// 8783
+
+struct Foo8783
+{
+ int[1] bar;
+}
+
+const Foo8783[1] foos8783;
+
+static this()
+{
+ foreach (i; 0 .. foos8783.length)
+ foos8783[i].bar[i] = 1; // OK
+ foreach (i, ref f; foos8783)
+ f.bar[i] = 1; // line 9, Error
+}
+
+/***************************************************/
// 9077
struct S9077a
Please sign in to comment.
Something went wrong with that request. Please try again.