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

Default function arguments have the wrong scope

    XMLWordPrintable

Details

    Description

      In ECMAScript, default function arguments are placed in their own environment record, which then acts as the parent scope for the function body. That means that

      console.log((function() {
              let a = 1;
              function f(fn = function(){ return a; }){ const a = 2; return fn() }
              return f();
          })())
      

      should print 1. However, in QML, it will print 2 because fn ends up in the scope of f's body, and thus uses the a from there instead of from the outer scope.

      Attachments

        Issue Links

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

          Activity

            People

              qtqmlteam Qt Qml Team User
              fabiankosmale Fabian Kosmale
              Vladimir Minenko Vladimir Minenko
              Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes