Skip to content
  • Kouhei Sutou's avatar
    8cb40fcd
    Fix ensure with yield context on break and return · 8cb40fcd
    Kouhei Sutou authored
    How to reproduce:
    
        class A
          def x
            yield
          ensure
            y
          end
    
          def y
          end
        end
    
        # Work
        A.new.x do
        end
    
        # Not work
        # trace:
        # 	[2] /tmp/a.rb:5:in A.x
        # 	[0] /tmp/a.rb:15
        # /tmp/a.rb:5: undefined method 'y' for main (NoMethodError)
        A.new.x do
          break
        end
    
        # trace:
        # 	[2] /tmp/a.rb:5:in A.call
        # 	[0] /tmp/a.rb:19
        # /tmp/a.rb:5: undefined method 'y' for main (NoMethodError)
        lambda do
          A.new.x do
            return
          end
        end.call
    
    `self` in ensure is broken when yield and break/return are used.
    8cb40fcd
    Fix ensure with yield context on break and return
    Kouhei Sutou authored
    How to reproduce:
    
        class A
          def x
            yield
          ensure
            y
          end
    
          def y
          end
        end
    
        # Work
        A.new.x do
        end
    
        # Not work
        # trace:
        # 	[2] /tmp/a.rb:5:in A.x
        # 	[0] /tmp/a.rb:15
        # /tmp/a.rb:5: undefined method 'y' for main (NoMethodError)
        A.new.x do
          break
        end
    
        # trace:
        # 	[2] /tmp/a.rb:5:in A.call
        # 	[0] /tmp/a.rb:19
        # /tmp/a.rb:5: undefined method 'y' for main (NoMethodError)
        lambda do
          A.new.x do
            return
          end
        end.call
    
    `self` in ensure is broken when yield and break/return are used.
Loading