Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[expressions] Variable length arguemnt functions accept 0 params
  • Loading branch information
m-kuhn committed Oct 27, 2016
1 parent 631db7b commit f52dfba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/core/qgsexpressionparser.yy
Expand Up @@ -223,7 +223,9 @@ expression:
exp_error(parser_ctx, "Function is not known");
YYERROR;
}
if ( QgsExpression::Functions()[fnIndex]->params() != 0 )
// 0 parameters is expected, -1 parameters means leave it to the
// implementation
if ( QgsExpression::Functions()[fnIndex]->params() > 0 )
{
exp_error(parser_ctx, QString( "%1 function is called with wrong number of arguments" ).arg( QgsExpression::Functions()[fnIndex]->name() ).toLocal8Bit().constData() );
YYERROR;
Expand Down
4 changes: 2 additions & 2 deletions tests/src/core/testqgsexpression.cpp
Expand Up @@ -2177,7 +2177,7 @@ class TestQgsExpression: public QObject
QgsExpressionContext context = QgsExpressionContextUtils::createFeatureBasedContext( f, QgsFields() );

QVariantList builderExpected;
QCOMPARE( QgsExpression( "array()" ).evaluate( &context ), QVariant( ) );
QCOMPARE( QgsExpression( "array()" ).evaluate( &context ), QVariant( builderExpected ) );
builderExpected << "hello";
QCOMPARE( QgsExpression( "array('hello')" ).evaluate( &context ), QVariant( builderExpected ) );
builderExpected << "world";
Expand Down Expand Up @@ -2303,7 +2303,7 @@ class TestQgsExpression: public QObject
QgsExpressionContext context = QgsExpressionContextUtils::createFeatureBasedContext( f, QgsFields() );

QVariantMap builderExpected;
QCOMPARE( QgsExpression( "map()" ).evaluate( &context ), QVariant( ) );
QCOMPARE( QgsExpression( "map()" ).evaluate( &context ), QVariant( builderExpected ) );
builderExpected[QStringLiteral( "1" )] = "hello";
QCOMPARE( QgsExpression( "map('1', 'hello')" ).evaluate( &context ), QVariant( builderExpected ) );
builderExpected[QStringLiteral( "2" )] = "world";
Expand Down

0 comments on commit f52dfba

Please sign in to comment.