Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-1095

Wrong scope generated for argument default value

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.13.2
    • 5.12.3, 5.13.1
    • Shiboken
    • None
    • e2774ff5350fa94352858672aa165a8ff22aa3b1 (pyside/pyside-setup/5.13)

    Description

      The heuristic used by shiboken to find the fully qualified enumeration name for default value does not correctly support expression.

      Let's consider the following code:

      enum class Color
      {
         Red = 1,
         Blue = 2
      };
      
      class Foo
      {
      public:   
         Foo(): mSize{0}, mColor{Color::Red} {}
         void configure(int size=10, Color c=Color::Red) { mSize = size; mColor = c;}
         Color getColor() const { return mColor; }
         int getSize() const { return mSize; }
         
      private:
         int mSize;
         Color mColor;
      };
      

      And the typesystem

      <?xml version="1.0"?>
      <typesystem package="test">
         <enum-type name="Color"/>
         <primitive-type name="int"/>
         <object-type name="Foo">
            <modify-function signature="configure(Color)">
               <modify-argument index="1">
                  <replace-default-expression with="cppSelf->getSize()"/>
               </modify-argument>
               <modify-argument index="2">
                  <replace-default-expression with="cppSelf->getColor()"/>
               </modify-argument>
            </modify-function>      
         </object-type>
      </typesystem>
      

      Here shiboken will not detect that the default value is an expression and not an enumeration value. It generates the following wrong code: the enumeration name (Color) is added as a prefix whereas it should not (here the default value has been replaced by an expression, not a valid enumeration value)

      ::Color cppArg1 = Color::cppSelf->getColor();
      if (pythonToCpp[1]) pythonToCpp[1](pyArgs[1], &cppArg1);
      

      The resolveScopePrefix function could check that the default value is actually an enumeration value and not an expression.

      Attachments

        1. pyside1095_repro.diff
          2 kB
          Friedemann Kleint

        Issue Links

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

          Activity

            People

              kleint Friedemann Kleint
              jumarock Jumarock Belpecajo
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes