Only implicitly convert strings to indexers

refs #8074
This commit is contained in:
Gunnar Beutner 2014-12-14 11:55:44 +01:00
parent 1cb0231c05
commit b40e95d9b6
2 changed files with 12 additions and 1 deletions

View File

@ -418,8 +418,9 @@ void icinga::BindToScope(Expression *& expr, ScopeSpecifier scopeSpec)
}
LiteralExpression *lexpr = dynamic_cast<LiteralExpression *>(expr);
ScriptFrame frame;
if (lexpr) {
if (lexpr && lexpr->Evaluate(frame).IsString()) {
Expression *scope = new GetScopeExpression(scopeSpec);
expr = new IndexerExpression(scope, lexpr, lexpr->GetDebugInfo());
}

View File

@ -234,6 +234,7 @@ BOOST_AUTO_TEST_CASE(advanced)
expr = ConfigCompiler::CompileText("<test>", "a = 3 b = 3");
BOOST_CHECK_THROW(expr->Evaluate(frame), ScriptError);
delete expr;
expr = ConfigCompiler::CompileText("<test>", "function() { 3 }()");
BOOST_CHECK(expr->Evaluate(frame) == 3);
@ -290,6 +291,15 @@ BOOST_AUTO_TEST_CASE(advanced)
expr = ConfigCompiler::CompileText("<test>", "7 & 15 > 6");
BOOST_CHECK(expr->Evaluate(frame));
delete expr;
expr = ConfigCompiler::CompileText("<test>", "\"a\" = 3");
BOOST_CHECK(expr->Evaluate(frame) == 3);
BOOST_CHECK(frame.Locals->Get("a") == 3);
delete expr;
expr = ConfigCompiler::CompileText("<test>", "3 = 3");
BOOST_CHECK_THROW(expr->Evaluate(frame), ScriptError);
delete expr;
}
BOOST_AUTO_TEST_SUITE_END()