Remove warning on assignment in while() conditions (for now)

master
Nicolas Hake 2018-04-04 21:42:24 +02:00
parent 75bfef6b06
commit 704994f1b9
2 changed files with 4 additions and 10 deletions

View File

@ -1570,7 +1570,10 @@ void C4AulCompiler::CodegenAstVisitor::visit(const ::aul::ast::WhileLoop *n)
{
int cond = AddJumpTarget();
PushLoop();
WarnOnAssignment(n->cond);
// 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
SafeVisit(n->cond);
active_loops.top().breaks.push_back(AddBCC(n->cond->loc, AB_CONDN));
if (SafeVisit(n->body))

View File

@ -105,15 +105,6 @@ TEST_F(AulDiagnosticsTest, suspicious_assignment)
RunCode("for (var a = 0; a == 1;) {}");
RunCode("for (var a = 0; a != 0;) {}");
}
{
EXPECT_WARNING(suspicious_assignment);
RunCode("var a = 0; while (a = 0) {}");
}
{
EXPECT_WARNING(suspicious_assignment).Times(0);
RunCode("var a = 0; while (a == 1) {}");
RunCode("var a = 0; while (a *= 1) {}");
}
{
EXPECT_WARNING(suspicious_assignment);
RunCode("var a = 0; return a = 0;");