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

Having variable name same as class method name produces an error

    XMLWordPrintable

Details

    Description

      class LinkedList {
          push(...values) {
              for (const value of values)
                  this.head = { value, next: this.head };
              return this;
          }
      
          values() {
              const values = []; // causes "Identifier values has already been declared"
              for (let node = this.head; node !== undefined; node = node.next)
                  values.push(node.value);
              return values;
          }
      }
      

      Code above works well both in Node and modern browsers.

      But this will work in QML:

      function clone(origin) {
          const length = origin.length;
          const clone = new Array(length); // works fine, even though have same name as function
          for (let i = 0; i < length; i++)
              clone[i] = origin[i];
          return clone;
      }
      
      function LinkedList() {
      }
      
      LinkedList.prototype.values = function () {
          const values = []; // fine too, but i suppose this function should implicitly have "values" name
          for (let node = this.head; node !== undefined; node = node.next)
              values.push(node.value);
          return values;
      }
      

      But this will fail again:

      function LinkedList() {
      }
      
      LinkedList.prototype.values = function values() {
          const values = []; // error here
          for (let node = this.head; node !== undefined; node = node.next)
              values.push(node.value);
          return values;
      }
      

      Attachments

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

        Activity

          People

            shausman Simon Hausmann
            evg656e Evgeny
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes