Skip to content

Commit

Permalink
Merge pull request #3528 from 9rnsr/fix12703
Browse files Browse the repository at this point in the history
[REG2.065] Issue 12703 - final class rejects members initialization
  • Loading branch information
AndrejMitrovic committed May 5, 2014
2 parents fd09d6b + c6a4932 commit cf56c8c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/class.c
Expand Up @@ -619,6 +619,8 @@ void ClassDeclaration::semantic(Scope *sc)
sc2->protection = PROTpublic;
sc2->explicitProtection = 0;
sc2->structalign = STRUCTALIGN_DEFAULT;
sc2->userAttribDecl = NULL;

if (baseClass)
{
alignsize = baseClass->alignsize;
Expand All @@ -632,7 +634,6 @@ void ClassDeclaration::semantic(Scope *sc)
else
structsize = Target::ptrsize * 2; // allow room for __vptr and __monitor
}
sc2->userAttribDecl = NULL;
size_t members_dim = members->dim;
sizeok = SIZEOKnone;

Expand Down Expand Up @@ -1452,14 +1453,16 @@ void InterfaceDeclaration::semantic(Scope *sc)
Scope *sc2 = sc->push(this);
sc2->stc &= STCsafe | STCtrusted | STCsystem;
sc2->parent = this;
sc2->inunion = 0;
if (com)
sc2->linkage = LINKwindows;
else if (cpp)
sc2->linkage = LINKcpp;
sc2->structalign = STRUCTALIGN_DEFAULT;
sc2->protection = PROTpublic;
sc2->explicitProtection = 0;
sc2->structalign = STRUCTALIGN_DEFAULT;
sc2->userAttribDecl = NULL;

structsize = Target::ptrsize * 2;
inuse++;

Expand Down
18 changes: 18 additions & 0 deletions src/struct.c
Expand Up @@ -202,13 +202,22 @@ void AggregateDeclaration::semantic2(Scope *sc)
}

Scope *sc2 = sc->push(this);
sc2->stc &= STCsafe | STCtrusted | STCsystem;
sc2->parent = this;
//if (isUnionDeclaration()) // TODO
// sc2->inunion = 1;
sc2->protection = PROTpublic;
sc2->explicitProtection = 0;
sc2->structalign = STRUCTALIGN_DEFAULT;
sc2->userAttribDecl = NULL;

for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
//printf("\t[%d] %s\n", i, s->toChars());
s->semantic2(sc2);
}

sc2->pop();
}

Expand All @@ -227,12 +236,21 @@ void AggregateDeclaration::semantic3(Scope *sc)
}

Scope *sc2 = sc->push(this);
sc2->stc &= STCsafe | STCtrusted | STCsystem;
sc2->parent = this;
if (isUnionDeclaration())
sc2->inunion = 1;
sc2->protection = PROTpublic;
sc2->explicitProtection = 0;
sc2->structalign = STRUCTALIGN_DEFAULT;
sc2->userAttribDecl = NULL;

for (size_t i = 0; i < members->dim; i++)
{
Dsymbol *s = (*members)[i];
s->semantic3(sc2);
}

sc2->pop();

// don't do it for unused deprecated types
Expand Down
13 changes: 13 additions & 0 deletions test/compilable/compile1.d
Expand Up @@ -612,3 +612,16 @@ void test12688()
s.foo.writeln12688; // ok
(s.foo).writeln12688; // ok <- ng
}

/***************************************************/
// 12703

struct S12703
{
this(int) {}
}

final class C12703
{
S12703 s = S12703(1);
}

0 comments on commit cf56c8c

Please sign in to comment.