Idea

Serge A avatar image
1 Like"
Serge A suggested

Stricter type checking for strings in arithmetic operators

Recently I encountered a bug in the model which was due to this Flexscript feature:

1631547902000.png

`string` values can be used in arithmetic expressions, and there are no warnings, exceptions, compilation errors, anything. `x` is silently converted to a numeric value zero. To make matter worse, integer 3 and string "3" are displayed identically in the debugger, and `x` can be a Variant.

While some programming languages (like Javascript, Powershell) do permit such code, they parse strings as numbers. The others do not permit such expressions without explicit type conversions.

I think it would be a good idea to make Flexscript type checker slightly stricter and require an explicit .toNum() conversion (or go the Javascript way). I understand that this is a breaking change, but otherwise there is absolutely no way to know if arithmetic expressions are evaluated correctly.

Relevant in FlexSim up to 21.2 Beta.

stringtonumflexscript
1631547902000.png (5.2 KiB)
5 |100000 characters needed characters left characters exceeded

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

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.