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

qmlcachegen: calling func(obj) clones obj instead of passing it by ref

XMLWordPrintable

      The following code fails if cachegen compiles the function bugTest():

      Window {
        id: window
        visible: true
      
        function foo(data: var) : void {
          data.count = 1
        }
      
        function check(data : var) : void {
          console.info("check", data.count === 1 ? "ok" : "fail")
        }
      
        function bugTest() : void {
          const data = ({})
          foo(data)
          check(data)
          // console.info(data.count) // uncomment to disable cachegen
        }
      
        Component.onCompleted: bugTest()
      }
      

      For some reason the object 'data' is cloned (CoW?) during the foo() function call. The expected behavior is that it is passed by reference.

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

            qtqmlteam Qt Qml Team User
            pdegoeje Pieter de Goeje
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes