mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	Set first line numbers for empty iseqs.
* compile.c (iseq_compile_each): for empty method, block and so on, `last_line` is not set so that line number of `putnil` instruction will be zero. This patch set `first_lineno` for such `putnil`. Problem is reported by deivid-rodriguez via Yuichiro Kaneko. * test/ruby/test_iseq.rb: add a test for this spec. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61457 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									7361587fff
								
							
						
					
					
						commit
						360c00572f
					
				
					 2 changed files with 36 additions and 1 deletions
				
			
		|  | @ -5413,8 +5413,10 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, const NODE *node, int poppe | ||||||
| { | { | ||||||
|     if (node == 0) { |     if (node == 0) { | ||||||
| 	if (!popped) { | 	if (!popped) { | ||||||
|  | 	    int lineno = ISEQ_COMPILE_DATA(iseq)->last_line; | ||||||
|  | 	    if (lineno == 0) lineno = FIX2INT(rb_iseq_first_lineno(iseq)); | ||||||
| 	    debugs("node: NODE_NIL(implicit)\n"); | 	    debugs("node: NODE_NIL(implicit)\n"); | ||||||
| 	    ADD_INSN(ret, ISEQ_COMPILE_DATA(iseq)->last_line, putnil); | 	    ADD_INSN(ret, lineno, putnil); | ||||||
| 	} | 	} | ||||||
| 	return COMPILE_OK; | 	return COMPILE_OK; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -357,4 +357,37 @@ class TestISeq < Test::Unit::TestCase | ||||||
|                    [["<class:D>@17", [[17, :class], |                    [["<class:D>@17", [[17, :class], | ||||||
|                                       [18, :end]]]]], collect_iseq.call(sample_iseq) |                                       [18, :end]]]]], collect_iseq.call(sample_iseq) | ||||||
|   end |   end | ||||||
|  | 
 | ||||||
|  |   def test_empty_iseq_lineno | ||||||
|  |     iseq = ISeq.compile(<<-EOS) | ||||||
|  |     # 1 | ||||||
|  |     # 2 | ||||||
|  |     def foo   # line 3 empty method | ||||||
|  |     end       # line 4 | ||||||
|  |     1.time do # line 5 empty block | ||||||
|  |     end       # line 6 | ||||||
|  |     class C   # line 7 empty class | ||||||
|  |     end | ||||||
|  |     EOS | ||||||
|  | 
 | ||||||
|  |     iseq.each_child{|ci| | ||||||
|  |       ary = ci.to_a | ||||||
|  |       type = ary[9] | ||||||
|  |       name = ary[5] | ||||||
|  |       line = ary[13].first | ||||||
|  |       case ary[9] | ||||||
|  |       when :method | ||||||
|  |         assert_equal "foo", name | ||||||
|  |         assert_equal 3, line | ||||||
|  |       when :class | ||||||
|  |         assert_equal '<class:C>', name | ||||||
|  |         assert_equal 7, line | ||||||
|  |       when :block | ||||||
|  |         assert_equal 'block in <compiled>', name | ||||||
|  |         assert_equal 5, line | ||||||
|  |       else | ||||||
|  |         raise "unknown ary: " + ary.inspect | ||||||
|  |       end | ||||||
|  |     } | ||||||
|  |   end | ||||||
| end | end | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 ko1
						ko1