Skip to content

Commit

Permalink
Merge pull request #3494 from WalterBright/refactor-isNogc
Browse files Browse the repository at this point in the history
small refactor
  • Loading branch information
9rnsr committed Apr 24, 2014
2 parents 0842392 + 06a501b commit 9871b57
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
28 changes: 11 additions & 17 deletions src/expression.c
Expand Up @@ -4088,22 +4088,19 @@ Expression *ArrayLiteralExp::semantic(Scope *sc)

semanticTypeInfo(sc, t0);

if (sc->func && !sc->intypeof)
if (sc->func && !sc->intypeof && elements && type->toBasetype()->ty == Tarray)
{
if (elements && type->toBasetype()->ty == Tarray)
for (size_t i = 0; i < elements->dim; i++)
{
for (size_t i = 0; i < elements->dim; i++)
if (!((*elements)[i])->isConst())
{
if (!((*elements)[i])->isConst())
if (sc->func->setGC())
{
if (sc->func->setGC())
{
error("array literals in @nogc function %s may cause GC allocation",
sc->func->toChars());
return new ErrorExp();
}
break;
error("array literals in @nogc function %s may cause GC allocation",
sc->func->toChars());
return new ErrorExp();
}
break;
}
}
}
Expand Down Expand Up @@ -4242,13 +4239,10 @@ Expression *AssocArrayLiteralExp::semantic(Scope *sc)
if (tkey == Type::terror || tvalue == Type::terror)
return new ErrorExp;

if (sc->func && !sc->intypeof)
if (sc->func && !sc->intypeof && keys->dim && sc->func->setGC())
{
if (keys->dim && sc->func->setGC())
{
error("associative array literal in @nogc function %s may cause GC allocation", sc->func->toChars());
return new ErrorExp;
}
error("associative array literal in @nogc function %s may cause GC allocation", sc->func->toChars());
return new ErrorExp;
}

type = new TypeAArray(tvalue, tkey);
Expand Down
10 changes: 2 additions & 8 deletions src/func.c
Expand Up @@ -3558,10 +3558,7 @@ bool FuncDeclaration::isSafe()

bool FuncDeclaration::isSafeBypassingInference()
{
if (flags & FUNCFLAGsafetyInprocess)
return false;
else
return isSafe();
return !(flags & FUNCFLAGsafetyInprocess) && isSafe();
}

bool FuncDeclaration::isTrusted()
Expand Down Expand Up @@ -3599,10 +3596,7 @@ bool FuncDeclaration::isNogc()

bool FuncDeclaration::isNogcBypassingInference()
{
if (flags & FUNCFLAGnogcInprocess)
return false;
else
return isNogc();
return !(flags & FUNCFLAGnogcInprocess) && isNogc();
}

/**************************************
Expand Down

0 comments on commit 9871b57

Please sign in to comment.