[#1611] set_trace_func/Array#fetch error — "Nathaniel Talbott" <nathaniel@...>

I've reduced the error I reported in ruby-talk:84013 to the following code:

17 messages 2003/10/11

stringy range bug

From: "Christoph" <chr_news@...>
Date: 2003-10-15 09:10:14 UTC
List: ruby-core #1634
Hi,

currently there is a bug in open ranges with 
identical boundaries  strings.

---
p ("a"..."a").to_a  # ["a"]
---


I also have a back log of old Range questions. 
Shouldn't a failure like

---
class Class
  alias succ superclass
end

class A
end

(A..Object).each {} # raises ... `<=>' for nil:NilClass (NoMethodError)
---

be fixed? (the patch should be straight forward) 
- and why isn't it possible to form ranges with incomparable 
boundaries  - this would make ranges more usefull
when iterating in trees - example

--
class Class
  alias succ superclass
end

class A
end
class B
end

(A..B)   # raises an argument error
---

rather than raising an error we could iterate up to the  
``least common successor'' - in our example this would
be Object?


/Christoph

 






Attachments (1)

string.diff (513 Bytes, text/x-diff)
--- string.c.1.176	2003-10-15 10:09:59.382163200 +0200
+++ string.c	2003-10-15 10:09:25.347153600 +0200
@@ -1174,9 +1174,12 @@
 {
     VALUE current, after_end;
     ID succ = rb_intern("succ");
+    int limits_cmp;
 
     StringValue(end);
-    if (rb_str_cmp(beg, end) > 0) return beg;
+    limits_cmp = rb_str_cmp(beg, end);
+
+    if ((limits_cmp > 0) || (excl && limits_cmp == 0)) return beg;
     after_end = rb_funcall(end, succ, 0, 0);
     current = beg;
     while (!rb_str_equal(current, after_end)) {

In This Thread

Prev Next