Disable suspicious_assigment warning in for conditions

While I do not agree with the idea of using straight assignments in
the condition of a for loop, people are divided on the argument and
lots of old code uses it.
master
Nicolas Hake 2018-07-23 08:27:16 +02:00
parent ddc68d7ad3
commit 81dff1b92a
2 changed files with 10 additions and 7 deletions

View File

@ -1451,7 +1451,10 @@ void C4AulCompiler::CodegenAstVisitor::visit(const ::aul::ast::ForLoop *n)
PushLoop();
if (n->cond)
{
WarnOnAssignment(n->cond);
// XXX:
// Assignments in the condition here should warn as well (like they do in
// if conditions) but a ton of code uses those assignments at the moment
// and people are divided about allowing it
cond = AddJumpTarget();
SafeVisit(n->cond);
active_loops.top().breaks.push_back(AddBCC(n->cond->loc, AB_CONDN));
@ -1561,6 +1564,10 @@ void C4AulCompiler::CodegenAstVisitor::visit(const ::aul::ast::DoLoop *n)
if (SafeVisit(n->body))
MaybePopValueOf(n->body);
int cond = AddJumpTarget();
// XXX:
// Assignments in the condition here should warn as well (like they do in
// if conditions) but a ton of code uses those assignments at the moment
// and people are divided about allowing it
SafeVisit(n->cond);
AddJumpTo(n->loc, AB_COND, body);
PopLoop(cond);
@ -1572,8 +1579,8 @@ void C4AulCompiler::CodegenAstVisitor::visit(const ::aul::ast::WhileLoop *n)
PushLoop();
// XXX:
// Assignments in the condition here should warn as well (like they do in
// for and if conditions) but a ton of code uses those assignments at the
// moment and people are divided about allowing it
// if conditions) but a ton of code uses those assignments at the moment
// and people are divided about allowing it
SafeVisit(n->cond);
active_loops.top().breaks.push_back(AddBCC(n->cond->loc, AB_CONDN));
if (SafeVisit(n->body))

View File

@ -96,10 +96,6 @@ TEST_F(AulDiagnosticsTest, suspicious_assignment)
RunCode("var a = 0; if (a == 1) {}");
RunCode("var a = 0; if (a += 1) {}");
}
{
EXPECT_WARNING(suspicious_assignment);
RunCode("for (var a = 0; a = 0;) {}");
}
{
EXPECT_WARNING(suspicious_assignment).Times(0);
RunCode("for (var a = 0; a == 1;) {}");