Project

General

Profile

Bug #13776

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

This bug was pointed out by al2o3-cr on the #ruby IRC channel on freenode. The following code sleeps for 3 seconds, even though `String#sleep` ``String#sleep`` is a private method. 

 ```ruby 
 

      module Test 
   
        refine String do 
     
          def sleep; end 
   
        end 
 
      end 

 

      puts "start" 
 
      "".sleep 3 
 
      puts "end" 
 ``` 

 This happens because `vm_call_method_each_type`, ``vm_call_method_each_type``, when running a method of type `VM_METHOD_TYPE_REFINED`, ``VM_METHOD_TYPE_REFINED``, uses `vm_call_zsuper` ``vm_call_zsuper`` to call inherited methods, which does not check the visibility of the method and directly executes it. I attached a patch which changes this code path and uses `vm_call_method` ``vm_call_method`` to trigger the code that honors method visibilities. I have not played extensively with this patch, but it at least does not seem to break any existing unit tests.

Back