Skip to content

Commit

Permalink
[expression] Show expected arg count if wrong args passed
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Apr 30, 2018
1 parent dcde8ee commit 27714fc
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/core/qgsexpressionparser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,26 @@ expression:
delete $3;
YYERROR;
}
if ( QgsExpression::Functions()[fnIndex]->params() != -1
&& !( QgsExpression::Functions()[fnIndex]->params() >= $3->count()
&& QgsExpression::Functions()[fnIndex]->minParams() <= $3->count() ) )
QgsExpressionFunction* func = QgsExpression::Functions()[fnIndex];
if ( func->params() != -1
&& !( func->params() >= $3->count()
&& func->minParams() <= $3->count() ) )
{
QgsExpression::ParserError::ParserErrorType errorType = QgsExpression::ParserError::FunctionWrongArgs;
parser_ctx->currentErrorType = errorType;
exp_error(&yyloc, parser_ctx, QString( "%1 function is called with wrong number of arguments" ).arg( QgsExpression::Functions()[fnIndex]->name() ).toLocal8Bit().constData() );
QString expectedMessage;
if (func->params() == func->minParams())
{
expectedMessage = QString("Expected %2" ).arg( func->params());
}
else
{
expectedMessage = QString("Expected between %2 and %4 max but got %3" ).arg( func->minParams(), func->params() );

This comment has been minimized.

Copy link
@nyalldawson

nyalldawson Apr 30, 2018

Collaborator

Should these messages be translated?

This comment has been minimized.

Copy link
@NathanW2

NathanW2 via email Apr 30, 2018

Author Member
}
exp_error(&yyloc, parser_ctx, QString( "%1 function is called with wrong number of arguments."
"%2 but got %3" ).arg( QgsExpression::Functions()[fnIndex]->name() )
.arg( expectedMessage )
.arg( $3->count() ).toLocal8Bit().constData() );
delete $3;
YYERROR;
}
Expand Down

0 comments on commit 27714fc

Please sign in to comment.