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

Switch/case taking return value of function directly randomly fails

    XMLWordPrintable

Details

    Description

      Following code randomly prints fail even if f() returns 0 or 1.

      import QtQuick 2.0
      
      Rectangle {
          width: 180
          height: 100
      
          Timer {
              running: true
              repeat: true
              interval: 100
              onTriggered: {
                  r();
              }
          }
      
          function f() {
              return Math.random() >= 0.5 ? 1 : 0;
          }
          function r() {
              switch (f()) {
              case 0:
              case 1:
                  print("0 or 1")
                  return;
              default:
                  console.log("fail")
              }
          }
      }
      

      Attachments

        For Gerrit Dashboard: QTBUG-41630
        # Subject Branch Project Status CR V

        Activity

          People

            laknoll Lars Knoll
            poikelin Joni Poikelin
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes