Project

General

Profile

Actions

Bug #8722

closed

Refinements remain active beyond the end of an evaled string

Added by Anonymous over 10 years ago. Updated over 10 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.1.0dev (2013-08-02 trunk 42320) [x86_64-darwin12.4.0]
[ruby-core:56329]

Description

=begin

The [[RefinementsSpec]] states:

"When main.using is invoked in a string given as the first argument of Kernel#eval, Kernel#instance_eval, or Module#module_eval, the end of the scope is the end of the string."

However, in this example script, String#upcase remains refined even after the call to eval() has finished:

module M
refine String do
def upcase
reverse
end
end
end

puts "hello world".upcase
puts eval(%{using M; "hello world".upcase})
puts "hello world".upcase

I would expect the output of this script to be:

HELLO WORLD
dlrow olleh
HELLO WORLD

Instead it is:

HELLO WORLD
dlrow olleh
dlrow olleh

=end

Actions #1

Updated by shugo (Shugo Maeda) over 10 years ago

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

This issue was solved with changeset r42396.
Charlie, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • vm_eval.c (eval_string_with_cref): copy cref to limit the scope of
    refienements in the eval string. [ruby-core:56329] [Bug #8722]

  • test/ruby/test_refinement.rb: related test.

Updated by naruse (Yui NARUSE) over 10 years ago

  • Status changed from Closed to Assigned

m = Module.new {
eval "module_function"

def test1() end
}
r = m.respond_to?(:test1)
の r が r42396 以降 true から false に変わっています

Updated by shugo (Shugo Maeda) over 10 years ago

  • Status changed from Assigned to Feedback

naruse (Yui NARUSE) wrote:

m = Module.new {
eval "module_function"

def test1() end
}
r = m.respond_to?(:test1)
の r が r42396 以降 true から false に変わっています

うーん、これ対応すべきでしょうか?
module_functionはスコープに作用するものなのでeval内で使用した場合の挙動は自明ではないと思います。

実際のアプリケーションでどんなケースで困るでしょうか?

Updated by matz (Yukihiro Matsumoto) over 10 years ago

仕様変更としてNEWSファイルに書けば良いことだと思います。

Matz.

Updated by naruse (Yui NARUSE) over 10 years ago

  • Status changed from Feedback to Assigned

matz (Yukihiro Matsumoto) wrote:

仕様変更としてNEWSファイルに書けば良いことだと思います。

Matz.

はい。「変えた」ということにし、NEWSに書いてあれば異議はありません。

Updated by shugo (Shugo Maeda) over 10 years ago

naruse (Yui NARUSE) wrote:

仕様変更としてNEWSファイルに書けば良いことだと思います。

Matz.

はい。「変えた」ということにし、NEWSに書いてあれば異議はありません。

ではそのように対応します。

ちなみにjruby 1.6.7で試したら今のtrunkの挙動と同じでした。

private/public/protectedなども同様ですね。

c = Class.new {
eval "private"
def foo
end
}
c.new.foo

他に何か同じような機能ってありましたっけ?

Actions #7

Updated by shugo (Shugo Maeda) over 10 years ago

  • Status changed from Assigned to Closed

This issue was solved with changeset r42437.
Charlie, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


Updated by naruse (Yui NARUSE) over 10 years ago

shugo (Shugo Maeda) wrote:

naruse (Yui NARUSE) wrote:

仕様変更としてNEWSファイルに書けば良いことだと思います。

Matz.

はい。「変えた」ということにし、NEWSに書いてあれば異議はありません。

ではそのように対応します。

ちなみにjruby 1.6.7で試したら今のtrunkの挙動と同じでした。

private/public/protectedなども同様ですね。

c = Class.new {
eval "private"
def foo
end
}
c.new.foo

他に何か同じような機能ってありましたっけ?

少なくとも rubyspec ではひっかかりませんでした。

Updated by naruse (Yui NARUSE) over 10 years ago

test for ruby-dev's mail-count/post_id

Updated by shugo (Shugo Maeda) over 10 years ago

naruse (Yui NARUSE) wrote:

private/public/protectedなども同様ですね。
(snip)
他に何か同じような機能ってありましたっけ?

少なくとも rubyspec ではひっかかりませんでした。

ご確認ありがとうございました。
何か他に指摘があれば説明を追加するようにします。

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0