Skip to content
  • nagachika's avatar
    d24cce8e
    merge revision(s)... · d24cce8e
    nagachika authored
    merge revision(s) bf1a6771,c1463625: [Backport #17012] [Backport #17014]
    
    	Fix non-numeric exclusive Range#minmax bug
    
    	The implementation of Range#minmax added in d5c60214 causes the
    	following incorrect behaviour:
    
    	  ('a'...'c').minmax => ["a", ["a", "b"]]
    
    	instead of
    
    	  ('a'...'c').minmax => ["a", "b"]
    
    	This is because the C implementation of Range#minmax (range_minmax)
    	directly delegates to the C implementation of Range#min (range_min) and
    	Range#max (range_max), without changing the execution context.
    
    	Range#max's C implementation (range_max), when given a non-numeric
    	exclusive range, delegates to super, which is meant to call
    	Enumerable#max. However, because range_max is called directly by
    	range_minmax, super calls Enumerable#minmax instead, causing the
    	incorrect nesting.
    
    	Perhaps it is possible to change the execution context in an optimized
    	manner, but the simplest solution seems to be to just explicitly
    	delegate from Range#minmax to Range#min and Range#max.
    
    	Use static variables in Range#minmax
    d24cce8e
    merge revision(s)...
    nagachika authored
    merge revision(s) bf1a6771,c1463625: [Backport #17012] [Backport #17014]
    
    	Fix non-numeric exclusive Range#minmax bug
    
    	The implementation of Range#minmax added in d5c60214 causes the
    	following incorrect behaviour:
    
    	  ('a'...'c').minmax => ["a", ["a", "b"]]
    
    	instead of
    
    	  ('a'...'c').minmax => ["a", "b"]
    
    	This is because the C implementation of Range#minmax (range_minmax)
    	directly delegates to the C implementation of Range#min (range_min) and
    	Range#max (range_max), without changing the execution context.
    
    	Range#max's C implementation (range_max), when given a non-numeric
    	exclusive range, delegates to super, which is meant to call
    	Enumerable#max. However, because range_max is called directly by
    	range_minmax, super calls Enumerable#minmax instead, causing the
    	incorrect nesting.
    
    	Perhaps it is possible to change the execution context in an optimized
    	manner, but the simplest solution seems to be to just explicitly
    	delegate from Range#minmax to Range#min and Range#max.
    
    	Use static variables in Range#minmax
Loading