Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upFix optimized `compare` when first arg is Nil #975
+1
−1
Conversation
brian-carroll
changed the title from
Prevent _List_Nil from being misidentified as a Tuple in _Utils_cmp
to
Fix optimized `compare` when first arg is Nil
Aug 25, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
brian-carroll commentedAug 25, 2018
•
edited
Edited 3 times
-
brian-carroll
edited Aug 25, 2018 (most recent)
-
brian-carroll
edited Aug 25, 2018
-
brian-carroll
edited Aug 25, 2018
-
brian-carroll
created Aug 25, 2018
Fix a "truthiness" bug in the PROD version of
_Utils_cmpThis line wants to check if the first argument is a Tuple. In PROD mode it uses
if (!x.$)to check for falsiness, since tuples have no$property in PROD mode.Unfortunately
_List_Nilcan also be passed in here, which is represented as{ $: 0 }. When that happens,x.$exists, but since it is falsy it passes the condition and is misidentified as a tuple! The tuple-related code then runs even though the inputs are lists. This can produce incorrect results, such as in the SSCCE below.This PR fixes it by using
hasOwnPropertyinstead of a truthiness check.(There are, of course, lots of ways to check for missing properties. Not sure what your preference is. I figured that checking the existence of a property should be more efficient than doing anything with its value. Dunno if that's right or not.)