Project

General

Profile

Actions

Bug #2179

closed

1.9.2において block のスコープがおかしいときがある

Added by takkanm (三村 益隆) over 14 years ago. Updated almost 13 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.2dev (2009-10-06 trunk 25243) [i386-darwin9.8.0]
Backport:
[ruby-dev:39439]

Description

=begin
rubyspecを流しているときに気づいたのですが、
ruby1.9.2 の trunk(rev 25243) にて blockのスコープが正しく動いてないように見えます。

対応するrubyspecは core/string/upto_spec.rb:21

% ruby -v
ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-darwin9.8.0]
% irb
ruby-1.9.1-p243 > a=[]; "25".upto("5"){|s|a<<s}; a
=> ["25"]

% ruby -v
ruby 1.9.2dev (2009-10-06 trunk 25243) [i386-darwin9.8.0]
% irb
ruby-1.9.2-head > a=[]; "25".upto("5"){|s|a<<s}; a
=> []

ただし、以下のケースだと正しく動いているようです。
ruby-1.9.2-head > a=[]; (1..10).each{|i| a<<i}; a
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
=end


Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Bug #2049: String#upto: Possible RegressionClosedmatz (Yukihiro Matsumoto)09/05/2009Actions
Actions #1

Updated by no6v (Nobuhiro IMAI) over 14 years ago

=begin
いまいです。

From: 益隆 三村 <redmine_at_ruby-lang.org>
Date: Tue, 6 Oct 2009 21:14:10 +0900

rubyspecを流しているときに気づいたのですが、
ruby1.9.2 の trunk(rev 25243) にて blockのスコープが正しく動いてないように見えます。

対応するrubyspecは core/string/upto_spec.rb:21

% ruby -v
ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-darwin9.8.0]
% irb
ruby-1.9.1-p243 > a=[]; "25".upto("5"){|s|a<<s}; a
=> ["25"]

% ruby -v
ruby 1.9.2dev (2009-10-06 trunk 25243) [i386-darwin9.8.0]
% irb
ruby-1.9.2-head > a=[]; "25".upto("5"){|s|a<<s}; a
=> []

これはブロックが一度も評価されてないからですね。

$ ruby1.9.1 -ve '"25".upto("5"){raise}'
ruby 1.9.1p243 (2009-07-16 revision 24175) [i486-linux]
-e:1:in block in <main>': unhandled exception from -e:1:in upto'
from -e:1:in `'
$ ruby1.9 -ve '"25".upto("5"){raise}'
ruby 1.9.2dev (2009-10-03 trunk 25201) [i686-linux]

両端が数値とみなせるときの String#upto の挙動の変更によるものだと思い
ます。これは書いておいた方がよいと思うので、パッチを書いてみました。

Nobuhiro IMAI
Key fingerprint = F39E D552 545D 7C64 D690 F644 5A15 746C BD8E 7106

Index: string.c

--- string.c (revision 25243)
+++ string.c (working copy)
@@ -2863,6 +2863,14 @@
*

  • a8 a9 b0 b1 b2 b3 b4 b5 b6
    
  • a8 a9 b0 b1 b2 b3 b4 b5 b6
    
    • If str and other_str contains only ascii numeric characters,
    • both are recognized as decimal numbers. In addition, the width of
    • string (e.g. leading zeros) is handled appropriately.
    • "9".upto("11").to_a   => ["9", "10", "11"]
      
    • "25".upto("5").to_a   => []
      
    • "07".upto("11").to_a  => ["07", "08", "09", "10", "11"]
      
    */

static VALUE

=end

Actions #2

Updated by matz (Yukihiro Matsumoto) over 14 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
Applied in changeset r25249.
=end

Actions #3

Updated by takkanm (三村 益隆) over 14 years ago

=begin
ミムラです。

2009年10月6日22:04 Nobuhiro IMAI :

これはブロックが一度も評価されてないからですね。

$ ruby1.9.1 -ve '"25".upto("5"){raise}'
ruby 1.9.1p243 (2009-07-16 revision 24175) [i486-linux]
-e:1:in block in <main>': unhandled exception from -e:1:in upto'
from -e:1:in `'
$ ruby1.9 -ve '"25".upto("5"){raise}'
ruby 1.9.2dev (2009-10-03 trunk 25201) [i686-linux]
両端が数値とみなせるときの String#upto の挙動の変更によるものだと思い
ます。これは書いておいた方がよいと思うので、パッチを書いてみました。
なるほど。数値のときの挙動に合わせるようになっていたのですね。
対応ありがとうございました。

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0