Skip to content
Permalink
Browse files

[expression] Show expected arg count if wrong args passed

  • Loading branch information
NathanW2 committed Apr 30, 2018
1 parent dcde8ee commit 27714fc5a1091336b8f926e1b3f622c3cbaa484c
Showing with 17 additions and 4 deletions.
  1. +17 −4 src/core/qgsexpressionparser.yy
@@ -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;
}

0 comments on commit 27714fc

Please sign in to comment.
You can’t perform that action at this time.