Revision: 2949 http://trac.macosforge.org/projects/ruby/changeset/2949 Author: lsansonetti@apple.com Date: 2009-11-02 23:22:20 -0800 (Mon, 02 Nov 2009) Log Message: ----------- let void-returning objc calls return the receiver instead of nil (patch by Thibault Martin-Lagardette) Modified Paths: -------------- MacRuby/trunk/compiler.cpp MacRuby/trunk/spec/macruby/language/objc_method_spec.rb Modified: MacRuby/trunk/compiler.cpp =================================================================== --- MacRuby/trunk/compiler.cpp 2009-11-03 05:20:38 UTC (rev 2948) +++ MacRuby/trunk/compiler.cpp 2009-11-03 07:22:20 UTC (rev 2949) @@ -6641,12 +6641,13 @@ ret_type = VoidTy; } + Value *self_arg = NULL; if (is_objc) { // self p = SkipFirstType(p); p = SkipStackSize(p); f_types.push_back(RubyObjTy); - Value *self_arg = arg++; + self_arg = arg++; params.push_back(self_arg); // sel @@ -6719,8 +6720,17 @@ else { retval = imp_call; } + GetFirstType(types, buf, sizeof buf); - retval = compile_conversion_to_ruby(buf, convert_type(buf), retval); + ret_type = convert_type(buf); + if (self_arg != NULL && ret_type == VoidTy) { + // If we are calling an Objective-C method that returns void, let's + // return the receiver instead of nil, for convenience purposes. + retval = self_arg; + } + else { + retval = compile_conversion_to_ruby(buf, ret_type, retval); + } ReturnInst::Create(context, retval, bb); return f; Modified: MacRuby/trunk/spec/macruby/language/objc_method_spec.rb =================================================================== --- MacRuby/trunk/spec/macruby/language/objc_method_spec.rb 2009-11-03 05:20:38 UTC (rev 2948) +++ MacRuby/trunk/spec/macruby/language/objc_method_spec.rb 2009-11-03 07:22:20 UTC (rev 2949) @@ -38,8 +38,8 @@ nil.self.should == nil end - it "returning void returns nil in Ruby" do - @o.methodReturningVoid.should == nil + it "returning void returns the receiver in Ruby" do + @o.methodReturningVoid.should == @o end it "returning nil returns nil in Ruby" do
participants (1)
-
source_changes@macosforge.org