Closed nohwnd closed 6 years ago
At the moment I throw exception when int is provided, but should throw when any value type or string is provided, and provide -Force
to skip the error and run the check. That way people still use this to prove quirks of the system, but won't get bitten in normal usage.
I am comparing two integers if they are the same reference and for some cases it work as expected, and for some it does not. To be exact it does not work as expected for values
1..100
. What I am guessing is that the language parser has a list of common constants in memory, and points to them to save memory (I think I read about similar optimization in .net but cannot replicate it in C# and can't find the source article. It does similar thing for strings called interning, but I could not find info about doing it for int.)In theory pointing to the same instance of 1 should not make a difference to the code, unless your code is actually checking whether or not the instances are the same. Then it makes difference and gives us unexpected results.
I guess comparing values types is not useful for real test code, because the expected answer is always false, unless you want to prove that there are some underlying micro-optimizations. So the best solution would be to throw an exception when the expected value is a ValueType or String.
Or is there a better solution?