Skip to content

Commit

Permalink
Merge pull request #8609 from thewilsonator/refactor-funcsem
Browse files Browse the repository at this point in the history
Refactor FunDecl semantic
merged-on-behalf-of: Razvan Nitu <RazvanN7@users.noreply.github.com>
  • Loading branch information
dlang-bot committed Sep 5, 2018
2 parents 8bdf59d + 3741497 commit d6ad81d
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions src/dmd/semantic3.d
Original file line number Diff line number Diff line change
Expand Up @@ -279,19 +279,9 @@ private extern(C++) final class Semantic3Visitor : Visitor
}

uint oldErrors = global.errors;
auto fds = FuncDeclSem3(funcdecl,sc);

if (funcdecl.frequires)
{
for (size_t i = 0; i < funcdecl.foverrides.dim; i++)
{
FuncDeclaration fdv = funcdecl.foverrides[i];
if (fdv.fbody && !fdv.frequires)
{
funcdecl.error("cannot have an in contract when overridden function `%s` does not have an in contract", fdv.toPrettyChars());
break;
}
}
}
fds.checkInContractOverrides();

// Remember whether we need to generate an 'out' contract.
immutable bool needEnsure = FuncDeclaration.needsFensure(funcdecl);
Expand Down Expand Up @@ -1356,3 +1346,36 @@ private extern(C++) final class Semantic3Visitor : Visitor
ad.semanticRun = PASS.semantic3done;
}
}

private struct FuncDeclSem3
{
// The FuncDeclaration subject to Semantic analysis
FuncDeclaration funcdecl;

// Scope of analysis
Scope* sc;
this(FuncDeclaration fd,Scope* s)
{
funcdecl = fd;
sc = s;
}

/* Checks that the overriden functions (if any) have in contracts if
* funcdecl has an in contract.
*/
void checkInContractOverrides()
{
if (funcdecl.frequires)
{
for (size_t i = 0; i < funcdecl.foverrides.dim; i++)
{
FuncDeclaration fdv = funcdecl.foverrides[i];
if (fdv.fbody && !fdv.frequires)
{
funcdecl.error("cannot have an in contract when overridden function `%s` does not have an in contract", fdv.toPrettyChars());
break;
}
}
}
}
}

0 comments on commit d6ad81d

Please sign in to comment.