Project

General

Profile

Bug #1074

crash on variable reference in BEGIN inside class

Added by mame (Yusuke Endoh) about 11 years ago. Updated almost 9 years ago.

Status:
Closed
Priority:
Normal
Target version:
ruby -v:
ruby 1.9.1p5000 (2009-01-31 trunk 21909) [i686-linux]
Backport:
[ruby-core:21690]

Description

=begin
(auto-registration seemed to fail to register [ruby-core:21657]
on redmine, so I do manually)

Hi,

2009/1/29 Soutaro Matsumoto matsumoto@soutaro.com:

Hi,

ruby 1.9 crashes on variable reference in BEGIN block inside class or
block like the following.

class C
x = 10
BEGIN { puts x }
end

lambda {
x = 10
BEGIN { puts x }
}

Prohibiting BEGIN in non-toplevel scope seems good for me.

$ rubysvn --version
ruby 1.9.1p5000 (2009-01-29 trunk 21874) [i386-darwin9.6.0]

$ rubysvn
class C
x = 10
BEGIN { puts x }
end

rubysvn: [BUG] get_local_var_idx: -1
ruby 1.9.1p5000 (2009-01-29 trunk 21874) [i386-darwin9.6.0]

-- control frame ----------
c:0002 p:-587732 s:0004 b:0004 l:000003 d:000003 TOP

c:0001 p:0000 s:0002 b:0002 l:000004 d:000004 TOP :54964

-- Ruby level backtrace information-----------------------------------------

-- C level backtrace information -------------------------------------------
0x119612 0 rubysvn 0x00119612
rb_vm_bugreport + 82
0x2cf6c 1 rubysvn 0x0002cf6c rb_warning + 444
0x2cfcb 2 rubysvn 0x0002cfcb rb_bug + 43
0xf3461 3 rubysvn 0x000f3461
rb_iseq_translate_threaded_code + 1345
0xf5a5c 4 rubysvn 0x000f5a5c
rb_parse_in_main + 3692
0xfdcf9 5 rubysvn 0x000fdcf9
rb_iseq_compile_node + 3193
0xfde1a 6 rubysvn 0x000fde1a
rb_iseq_compile_node + 3482
0xfee68 7 rubysvn 0x000fee68
rb_iseq_compile_node + 7656
0xf6b67 8 rubysvn 0x000f6b67
rb_parse_in_main + 8055
0xf84b3 9 rubysvn 0x000f84b3
rb_parse_in_main + 14531
0xfd4fc 10 rubysvn 0x000fd4fc
rb_iseq_compile_node + 1148
0x100dbb 11 rubysvn 0x00100dbb
ruby_debug_breakpoint + 3579
0x100e71 12 rubysvn 0x00100e71
rb_iseq_new_main + 97
0xbe7e6 13 rubysvn 0x000be7e6 ruby_set_argv

  • 2326 0x108dff 14 rubysvn 0x00108dff rb_vm_call_cfunc + 175 0xbea9d 15 rubysvn 0x000bea9d ruby_process_options + 157 0x3210b 16 rubysvn 0x0003210b ruby_options
  • 123 0x2147 17 rubysvn 0x00002147 main + 87 0x20b6 18 rubysvn 0x000020b6 start + 54

[NOTE]
You may encounter a bug of Ruby interpreter. Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html

Thank you for your report, Soutaro.

I fixed this issue in r21876 by changing syntax to prohibit
BEGIN in non-toplevel scope.
At Yugui's discretion, the change is included in 1.9.1 release.

$ ruby -ve 'class Foo; BEGIN {}; end'
ruby 1.9.1p0 (2009-01-30 revision 21907) [i686-linux]
-e:1: syntax error, unexpected keyword_BEGIN
class Foo; BEGIN {}; end
^

Currently, the change is applied to only branches/ruby_1_9_1.
Matz, what do you think of it for trunk?

--
Yusuke ENDOH mame@tsg.ne.jp
=end

#1

Updated by ko1 (Koichi Sasada) about 11 years ago

  • Assignee changed from matz (Yukihiro Matsumoto) to ko1 (Koichi Sasada)

=begin

=end

#2

Updated by ko1 (Koichi Sasada) about 11 years ago

  • Assignee changed from ko1 (Koichi Sasada) to matz (Yukihiro Matsumoto)

=begin

=end

#3

Updated by matz (Yukihiro Matsumoto) about 11 years ago

=begin
Hi,

In message "Re: [Bug #1074] crash on variable reference in BEGIN inside class"
on Sat, 31 Jan 2009 09:32:11 +0900, Yusuke Endoh redmine@ruby-lang.org writes:

|I fixed this issue in r21876 by changing syntax to prohibit
|BEGIN in non-toplevel scope.
|At Yugui's discretion, the change is included in 1.9.1 release.

|Currently, the change is applied to only branches/ruby_1_9_1.
|Matz, what do you think of it for trunk?

I agreed. Could you commit to trunk as well.

                        matz.

=end

#4

Updated by wanabe (_ wanabe) about 10 years ago

=begin
This change, r21876, should be applied to trunk, shouldn't this?
It is allowed already.
=end

#5

Updated by wanabe (_ wanabe) about 10 years ago

  • Status changed from Open to Closed

=begin
fixed by r26347. Thanks a lot.
=end

Also available in: Atom PDF