Idea

Jeremy R avatar image
1 Like"
Jeremy R suggested Jeremy R edited

Prevent implicit type conversion when reading from an array

Arrays do not enforce type consistency when reading from an array.

For example, consider the following code

int testInt = 2;
Array testArray = [testInt];
string testString = testArray[1];
return testString;

In FlexSim 2021, this returns the string "2". (In FlexSim 2018, this returns a null string.)

However, consider the following code

int testInt = 2;
string testString = testInt;
return testString;

If you run that code (in either 2018 or 2021), you get this error message: "Could not resolve correct operator for = operation. Left side type is string&, right type is int&"

In my opinion, it would be better if running the first block of code returned that same error message. I find implicit type conversion like that to be quite dangerous, as it makes it easy for bugs to go unnoticed.

Importantly, this does not work in reverse. If you try to cast a string representation of an integer (e.g. "2") to an integer via an array, the integer will be 0, not the integer value represented by the string.

arraytypecastingtype conversion
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

No Comments

·

Write a Comment

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Your Opinion Counts

Share your great idea, or help out by voting for other people's ideas.