Merge pull request #11190 from kinke/postblit

Fix Issue 11292 - Cannot re-initialize a const field in postblit
merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
This commit is contained in:
The Dlang Bot 2020-05-27 13:14:06 +02:00 committed by GitHub
commit 7910886040
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View file

@ -89,15 +89,18 @@ bool modifyFieldVar(Loc loc, Scope* sc, VarDeclaration var, Expression e1)
if (s)
fd = s.isFuncDeclaration();
if (fd &&
((fd.isCtorDeclaration() && var.isField()) ||
(fd.isStaticCtorDeclaration() && !var.isField())) &&
((var.isField() && (fd.isCtorDeclaration() || fd.isPostBlitDeclaration())) ||
(!var.isField() && fd.isStaticCtorDeclaration())) &&
fd.toParentDecl() == var.toParent2() &&
(!e1 || e1.op == TOK.this_))
{
bool result = true;
var.ctorinit = true;
//printf("setting ctorinit\n");
if (!fd.isPostBlitDeclaration())
{
var.ctorinit = true;
//printf("setting ctorinit\n");
}
if (var.isField() && sc.ctorflow.fieldinit.length && !sc.intypeof)
{

View file

@ -0,0 +1,5 @@
struct S
{
immutable int x;
this(this) { x = 1; }
}