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

QML implicitly converts string to int despite type annotations

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P3: Somewhat important
    • 6.9
    • 6.6.0 Beta2
    • QML: Compiler, QML: Tooling
    • None

    Description

      Consider the following code

      function greaterThanTwo(input: int) : bool
      {
          return input > 2
      }
      
      property string foo: ...
      
      property bool bar: greaterThanTwo(foo) 

      qmlsc will happily compile this code and qmllint has no complaints about it either. Passing foo to greaterThanTwo implicitly converts the string to int, which may or may not work.

      This is probably the expected behavior from a JS point of view, so I wouldn't necessarily call this a bug. With my C++ mindset however I find this very unexpected and would have liked this to not work, since it suggests that there is a bug in my code.

      I think it would be good if QML was stricter about this kind of conversion, if only as an opt-in to not break existing code

       

      Attachments

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

        Activity

          People

            qtqmlteam Qt Qml Team User
            nicolasfella Nicolas Fella
            Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes