Bug #5614

Proc#source_location & #inspect shows wrong line number when chained

Added by TzeYang Ng almost 4 years ago. Updated over 3 years ago.

[ruby-core:40936]
Status:Closed
Priority:Normal
Assignee:-
ruby -v:ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux] Backport:

Description

When procs are chained, the line number for each proc is mis-calculated to be the 1st proc's line-number.

Eg.

class Foo
  def bar(&blk)
    pp blk.source_location
    self
  end
end

Foo.new.bar do
  puts 'b1'
end.bar do
  puts 'b2'
end

The 1st & 2nd procs show the same line number, when they shouldn't.

Though i listed the target version as 1.9.2, this behaviour is consistent for all versions of mri.

proc_test.rb Magnifier (969 Bytes) TzeYang Ng, 11/11/2011 02:17 PM

Associated revisions

Revision 34031
Added by Nobuyoshi Nakada over 3 years ago

  • parse.y (primary): point method name line. [Bug #5614]

Revision 34031
Added by Nobuyoshi Nakada over 3 years ago

  • parse.y (primary): point method name line. [Bug #5614]

History

#1 Updated by Yasushi ANDO over 3 years ago

It may not a bug but a specification. A block returns the number of a line in which the block is defined for its "source_location." When you use procs instead of blocks, it returns the values you expected.

Code:
1 require 'pp'
2 class Foo
3 def bar(&blk)
4 pp blk.source_location
5 self
6 end
7 end
8
9 Foo.new.bar(&proc{
10 puts 'b1'
11 }).bar(&proc{
12 puts 'b2'
13 })

Result:
$ ruby procs.rb
["procs.rb", 9]
["procs.rb", 11]

#2 Updated by Nobuyoshi Nakada over 3 years ago

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

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


  • parse.y (primary): point method name line. [Bug #5614]

Also available in: Atom PDF