A bug or not ?

Discussions about product bugs & problems!
Note: This is no replacement for the Official ETM Support!
3 posts • Page 1 of 1
fmulder
Posts:330
Joined: Wed Feb 03, 2010 9:46 am

A bug or not ?

Post by fmulder »

We ported some of our script code to 3.17. A class method that worked perfectly fine in 3.16 will now show a warning in 3.17. I just don't know wether this is a bug or a feature ?

The issue can best be demonstrated in the following stripped down code. When you use the following code in a regular (non-class method) then everything will work fine. When you use this code in the method of a class then the LogViewer will say "dyn_mixed, Given datatype does not match with needed type 'dyn_string'" ????

Code: Select all

class MyClass{
  public dyn_string ConvertAMixedToADynString()
  {
    dyn_mixed dmJustADummyMixed = makeDynMixed( 12, "hello", 3.14 );
    
    return dmJustADummyMixed;   // <==================
  }
}  
To summarize:
  • a class method with return type dyn_string doesn't like it when you return a dyn_mixed ?
  • a regular function is ok with this !
  • the sample code shown below works fine in 3.16 !
Now is this a feature or is this a bug ? Did they make the check for the return type better in 3.17 ? And why does the class method work different compared to a regular function ?

Here's a full working demo ! (just paste in a panel)

Code: Select all

class MyDemoClass{

  // This class demonstrates na issue that we
  // encountered when upgrading to 3.17 !
  // Note how the method 'MyDemoClass.ConvertAMixedToADynString'
  // is exactly the same as the 'regular' (non class method) function 'ConvertAMixedToADynString'
  public dyn_string ConvertAMixedToADynString()
  {
    dyn_mixed dmJustADummyMixed = makeDynMixed( 12, "hello", 3.14 );

    // The following line will cause a warning in the LogViewer
    //  'WARNING,    28/ctrl, dyn_mixed, Given datatype does not match with needed type 'dyn_string''
    //
    // NOTE: When you run this code in 3.16 then you will not get any warning !??
    return dmJustADummyMixed;

    // You can 'fix' (of workaround) this issue
    // by specifying
    //    return (dyn_string)dmJustADummyMixed;
    //            ^^^^^^^^^^^
  }


};

dyn_string ConvertAMixedToADynString()
{
    // This function will work perfectly fine. It will convert
    // the 'dyn_mixed' to a 'dyn_string' (and there will be no warnings !
    dyn_mixed dmJustADummyMixed = makeDynMixed( 55, "World", 2.35 );
    return dmJustADummyMixed;
}

main()
{

  // we noticed that one of our class methods would suddenly produce warnings
  // in the LogViewer. Our function would actually do something
  // like:
  //    dyn-string GetDataSources()
  //    {
  //       return mappingKeys( m3bDBDatabase.datasources );;
  //    }
  // NOTE that this method worked perfectly fine in 3.16 !

  // We first call the regular function (non class method)
  // Works fine, no warnings in the logviewer
  dyn_string dstrData = ConvertAMixedToADynString();
  DebugN( "Result from regular function = " + dstrData );

  // The class method is exactly the same
  // But now there's a warning in the LogViewer !
  //   'WARNING,    28/ctrl, dyn_mixed, Given datatype does not match with needed type 'dyn_string''
  MyDemoClass demo1;
  dstrData = demo1.ConvertAMixedToADynString();
  DebugN( "same code from a class = " + dstrData );

  // Both the regular function and the class method
  // will return the proper data.
  // The only issue is that the class method gives the warning ! (since 3.17P004)

}
Let me know what you think.

Share the fun
Frenk Mulder

kilianvp
Posts:443
Joined: Fri Jan 16, 2015 10:29 am

Re: A bug or not ?

Post by kilianvp »

i have noticed that wincc oa has recently started to pay attention to types and is no longer casting everything laxly. maybe this is another step towards type safety

Andorhal
Posts:127
Joined: Wed Nov 12, 2014 8:04 am

Re: A bug or not ?

Post by Andorhal »

Its a feature in 3.17.
And thanks Kilian, that is an excellent summary ;-)

3 posts • Page 1 of 1