[#122643] [Ruby Bug#21498] Windows - Ruby Overrides C Library APIs thus breaking them — "cfis (Charlie Savage) via ruby-core" <ruby-core@...>

Issue #21498 has been reported by cfis (Charlie Savage).

9 messages 2025/07/02

[#122658] [Ruby Feature#21501] Include native filenames in backtraces as sources for native methods — "ivoanjo (Ivo Anjo) via ruby-core" <ruby-core@...>

Issue #21501 has been reported by ivoanjo (Ivo Anjo).

10 messages 2025/07/05

[#122665] [Ruby Bug#21503] \p{Word} does not match on \p{Join_Control} while docs say it does — "procmarco (Marco Concetto Rudilosso) via ruby-core" <ruby-core@...>

SXNzdWUgIzIxNTAzIGhhcyBiZWVuIHJlcG9ydGVkIGJ5IHByb2NtYXJjbyAoTWFyY28gQ29uY2V0

8 messages 2025/07/07

[#122734] [Ruby Bug#21511] Use-after-free of the execution context after the fiber object carrying it is freed in GC — "tuonigou (tianyang sun) via ruby-core" <ruby-core@...>

Issue #21511 has been reported by tuonigou (tianyang sun).

10 messages 2025/07/14

[#122797] [Ruby Feature#21515] Add `&return` as sugar for `x=my_calculation; return x if x` — "nhorton (Noah Horton) via ruby-core" <ruby-core@...>

Issue #21515 has been reported by nhorton (Noah Horton).

13 messages 2025/07/16

[#122842] [Ruby Feature#21518] Statistical helpers to `Enumerable` — "Amitleshed (Amit Leshed) via ruby-core" <ruby-core@...>

SXNzdWUgIzIxNTE4IGhhcyBiZWVuIHJlcG9ydGVkIGJ5IEFtaXRsZXNoZWQgKEFtaXQgTGVzaGVk

12 messages 2025/07/23

[#122847] [Ruby Feature#21520] Feature Proposal: Enumerator::Lazy#peek — "nuzair46 (Nuzair Rasheed) via ruby-core" <ruby-core@...>

SXNzdWUgIzIxNTIwIGhhcyBiZWVuIHJlcG9ydGVkIGJ5IG51emFpcjQ2IChOdXphaXIgUmFzaGVl

12 messages 2025/07/24

[ruby-core:122774] [Ruby Feature#21513] Raise on converting endless range to set

From: "Dan0042 (Daniel DeLorme) via ruby-core" <ruby-core@...>
Date: 2025-07-15 03:28:08 UTC
List: ruby-core #122774
Issue #21513 has been updated by Dan0042 (Daniel DeLorme).


Raising an error should be the case for ANY endless range operations that result in an infinite loop and memory consumption. This is a very costly and hard to debug failure mode, and it happens for a large number of endless range methods.

----------------------------------------
Feature #21513: Raise on converting endless range to set
https://bugs.ruby-lang.org/issues/21513#change-114052

* Author: viralpraxis (Iaroslav Kurbatov)
* Status: Open
----------------------------------------
Converting endless range to array raises:

``` shell
ruby -e '(1..).to_a'
-e:1:in 'Range#to_a': cannot convert endless range to an array (RangeError)
	from -e:1:in '<main>'
```

but converting to set does not:

``` shell
ruby -e '(1..).to_set # hangs'
```

I think it makes to raise in both cases for consistency. Something like this should do the trick:

``` diff
diff --git i/prelude.rb w/prelude.rb
index f49cada637..11bfa3fc95 100644
--- i/prelude.rb
+++ w/prelude.rb
@@ -30,6 +30,10 @@ module Enumerable
   # Makes a set from the enumerable object with given arguments.
   # Passing arguments to this method is deprecated.
   def to_set(*args, &block)
+    if self.class == Range && self.end.nil?
+      raise RangeError, "cannot convert endless range to a set"
+    end
+
     klass = if args.empty?
       Set
     else
diff --git i/test/ruby/test_range.rb w/test/ruby/test_range.rb
index f875c0ab40..27b968641b 100644
--- i/test/ruby/test_range.rb
+++ w/test/ruby/test_range.rb
@@ -1541,4 +1541,11 @@ def test_overlap?
     assert_not_operator((1...3), :overlap?, (3..4))
     assert_not_operator((...3), :overlap?, (3..))
   end
+
+  def test_to_set
+    assert_equal(Set[], (1..-1).to_set)
+    assert_equal(Set[1, 2, 3], (1..3).to_set)
+
+    assert_raise(RangeError) { (239..).to_set }
+  end
 end
```

If this patch is accepted, I'll open a PR.

``` shell
./ruby -v
ruby 3.5.0dev (2025-07-14T20:34:32Z master a6d483971a) +PRISM [x86_64-linux]
```




-- 
https://bugs.ruby-lang.org/
______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/


In This Thread