Fix #269
This commit is contained in:
parent
c09abbdab6
commit
27a423e3fa
|
@ -1 +1 @@
|
||||||
Subproject commit a059356c94e949625417ea98c9c1c59186fa285f
|
Subproject commit b5791923695c755aae9cf313555fd20c5b0993d9
|
|
@ -24,7 +24,7 @@ class CommaExpressionCheck : BaseAnalyzer
|
||||||
|
|
||||||
override void visit(const Expression ex)
|
override void visit(const Expression ex)
|
||||||
{
|
{
|
||||||
if (ex.items.length > 1)
|
if (ex.items.length > 1 && interest > 0)
|
||||||
{
|
{
|
||||||
addErrorMessage(ex.line, ex.column, KEY,
|
addErrorMessage(ex.line, ex.column, KEY,
|
||||||
"Avoid using the comma expression.");
|
"Avoid using the comma expression.");
|
||||||
|
@ -32,5 +32,19 @@ class CommaExpressionCheck : BaseAnalyzer
|
||||||
ex.accept(this);
|
ex.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override void visit(const AssignExpression ex)
|
||||||
|
{
|
||||||
|
++interest;
|
||||||
|
ex.accept(this);
|
||||||
|
--interest;
|
||||||
|
}
|
||||||
|
|
||||||
|
invariant
|
||||||
|
{
|
||||||
|
assert(interest >= 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int interest;
|
||||||
|
|
||||||
private enum KEY = "dscanner.suspicious.comma_expression";
|
private enum KEY = "dscanner.suspicious.comma_expression";
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ class IfElseSameCheck : BaseAnalyzer
|
||||||
|
|
||||||
override void visit(const AssignExpression assignExpression)
|
override void visit(const AssignExpression assignExpression)
|
||||||
{
|
{
|
||||||
const AssignExpression e = cast(const AssignExpression) assignExpression.assignExpression;
|
auto e = cast(const AssignExpression) (cast(const Expression) assignExpression.expression).items[$ - 1];
|
||||||
if (e !is null && assignExpression.operator == tok!"="
|
if (e !is null && assignExpression.operator == tok!"="
|
||||||
&& e.ternaryExpression == assignExpression.ternaryExpression)
|
&& e.ternaryExpression == assignExpression.ternaryExpression)
|
||||||
{
|
{
|
||||||
|
|
|
@ -93,7 +93,7 @@ class UnmodifiedFinder:BaseAnalyzer
|
||||||
assignExpression.ternaryExpression.accept(this);
|
assignExpression.ternaryExpression.accept(this);
|
||||||
guaranteeUse--;
|
guaranteeUse--;
|
||||||
interest--;
|
interest--;
|
||||||
assignExpression.assignExpression.accept(this);
|
assignExpression.expression.accept(this);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
assignExpression.accept(this);
|
assignExpression.accept(this);
|
||||||
|
|
|
@ -154,17 +154,17 @@ class UnusedVariableCheck : BaseAnalyzer
|
||||||
override void visit(const AssignExpression assignExp)
|
override void visit(const AssignExpression assignExp)
|
||||||
{
|
{
|
||||||
assignExp.ternaryExpression.accept(this);
|
assignExp.ternaryExpression.accept(this);
|
||||||
if (assignExp.assignExpression !is null)
|
if (assignExp.expression !is null)
|
||||||
{
|
{
|
||||||
interestDepth++;
|
interestDepth++;
|
||||||
assignExp.assignExpression.accept(this);
|
assignExp.expression.accept(this);
|
||||||
interestDepth--;
|
interestDepth--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const TemplateDeclaration templateDeclaration)
|
override void visit(const TemplateDeclaration templateDeclaration)
|
||||||
{
|
{
|
||||||
auto inAgg = inAggregateScope;
|
immutable inAgg = inAggregateScope;
|
||||||
inAggregateScope = true;
|
inAggregateScope = true;
|
||||||
templateDeclaration.accept(this);
|
templateDeclaration.accept(this);
|
||||||
inAggregateScope = inAgg;
|
inAggregateScope = inAgg;
|
||||||
|
|
|
@ -113,13 +113,13 @@ class XMLPrinter : ASTVisitor
|
||||||
|
|
||||||
override void visit(const AssignExpression assignExpression)
|
override void visit(const AssignExpression assignExpression)
|
||||||
{
|
{
|
||||||
if (assignExpression.assignExpression is null)
|
if (assignExpression.expression is null)
|
||||||
output.writeln("<assignExpression>");
|
output.writeln("<expression>");
|
||||||
else
|
else
|
||||||
output.writeln("<assignExpression operator=\"",
|
output.writeln("<expression operator=\"",
|
||||||
xmlAttributeEscape(str(assignExpression.operator)), "\">");
|
xmlAttributeEscape(str(assignExpression.operator)), "\">");
|
||||||
assignExpression.accept(this);
|
assignExpression.accept(this);
|
||||||
output.writeln("</assignExpression>");
|
output.writeln("</expression>");
|
||||||
}
|
}
|
||||||
|
|
||||||
override void visit(const AtAttribute atAttribute)
|
override void visit(const AtAttribute atAttribute)
|
||||||
|
|
Loading…
Reference in New Issue