Project

General

Profile

Actions

Bug #15719

closed

to_enum を使用した場合にバックトレースが意図しないものになる

Added by krororo (Ryota Kitazawa) about 5 years ago. Updated about 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.6.2p47 (2019-03-13 revision 67232) [x86_64-linux]
[ruby-core:91911]

Description

to_enum を使用するとバックトレースの呼び出し元が実行ファイルの1行目 each と出力されます。
再現コードの 8 行目や、to_enum に指定した foo メソッドがバックトレースに出てくるべきかと思います。

再現コード

def foo
  return to_enum(__method__) unless block_given?
  raise 'error!'
  yield 1
end

enum = foo
p enum.next

実行結果

$ ruby /tmp/test.rb
Traceback (most recent call last):
	1: from /tmp/test.rb:1:in `each'
/tmp/test.rb:3:in `foo': error! (RuntimeError)

see: https://github.com/ruby/csv/issues/82

Actions #1

Updated by mame (Yusuke Endoh) about 5 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r67326.


Fix a wrong lineno in backtrace for cfunc

lineno is an int, and INT2FIX(0) was assigned.

[Bug #15719] [ruby-core:91911]

Updated by mame (Yusuke Endoh) about 5 years ago

ありがとうございます。とりあえず明らかな型バグがあったので修正しました。

$ ./miniruby /tmp/test.rb 
Traceback (most recent call last):
	1: from /tmp/test.rb:in `each'
/tmp/test.rb:3:in `foo': error! (RuntimeError)

↑のように、嘘の行番号は出なくなりました。

Actions

Also available in: Atom PDF

Like0
Like0Like0