Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-140191

qml: parser doesn't like lambdas in statementlists

XMLWordPrintable

      The parser doesn't like lamdas in statementlist:

      import QtQuick
      
      Item {
      function f(){
              (function() {}()) // this is fine
               function() {}() // can't be parsed: Expected token `identifier'
          }
      }
      

      In qqmljs.g, it seems that we have this code:

      StatementListItem: ExpressionStatementLookahead T_FORCE_DECLARATION Declaration Semicolon;
      /.
          case $rule_number: {
              sym(1).Node = new (pool) AST::StatementList(sym(3).FunctionDeclaration);
          } break;
      ./
      

      and ExpressionStatementLookahead does seem to insert a T_FORCE_DECLARATION when it sees a T_FUNCTION:

      -- Spec says it should have a "[lookahead ∉ { {, function, class, let [ }]" before the Expression statement.
      -- This is implemented with the rule below that is run before any statement and inserts a T_EXPRESSION_STATEMENT_OK
      -- token if it's ok to parse as an expression statement.
      ExpressionStatementLookahead: ;
      /:
      #define J_SCRIPT_EXPRESSIONSTATEMENTLOOKAHEAD_RULE $rule_number
      :/
      /.
          case $rule_number: {
              int token = lookaheadToken(lexer);
              if (token == T_LBRACE)
                  pushToken(T_FORCE_BLOCK);
              else if (token == T_FUNCTION || token == T_CLASS || token == T_LET || token == T_CONST)
                  pushToken(T_FORCE_DECLARATION);
          } break;
      ./
      

      The T_FORCE_DECLARATION seems to force a declaration, but a lambda expression is no declaration (its an expression statement) and therefore it fails while trying to parse the identifier expected after the T_FUNCTION.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            qtqmlteam Qt Qml Team User
            sami.shalayel Sami Shalayel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes