Bug 705420

Summary: ruby-bindings: function parameter with default value cannot be parsed
Product: [openSUSE] openSUSE 11.4 Reporter: Jiří Suchomel <jsuchome>
Component: YaST2Assignee: Josef Reidinger <jreidinger>
Status: RESOLVED FIXED QA Contact: Jiri Srain <jsrain>
Severity: Normal    
Priority: P3 - Medium CC: kkaempf, mvidner
Version: Final   
Target Milestone: ---   
Hardware: Other   
OS: Other   
Whiteboard:
Found By: Development Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Jiří Suchomel 2011-07-13 12:36:13 UTC
module KerberosClient

  def self.read(params={})
  ...
  end

end


ruby-bidnings does not correctly realize number of arguments:

Y2DIR= LD_LIBRARY_PATH= /usr/bin/ycpc -c -M. -I. -q  Kerberos.ycp
ruby/YRubyNamespace.cc(YRubyNamespace):239  [Y2Ruby] going to parse signature: 'any( any)'
ruby/YRubyNamespace.cc(YRubyNamespace):239  [Y2Ruby] going to parse signature: 'any( any)'
ruby/YRubyNamespace.cc(YRubyNamespace):239  [Y2Ruby] going to parse signature: 'any( )'
Kerberos.ycp:279  [Parser] Excessive parameter in call to KerberosClient::read(...)
Comment 1 Duncan Mac-Vicar 2011-07-21 08:21:30 UTC
I discussed this bug with Jiri during the workshop. The reason it happens is
because the bindings use Method#arity when it should probably use
Method#parameters (as detailed in the ruby-doc).

Method#arity returns negative numbers when there are optional parameters and
this causes the crash. So YCP should always call ruby passing _all_ parameters
of a ruby method with optional arguments.

Sadly, the advertised Merthod#parameters
(http://www.ruby-doc.org/core/classes/Method.html#M001075) does not seem to be
available in the interpreter.
Comment 2 Klaus Kämpf 2011-07-25 09:08:50 UTC
(In reply to comment #1)
> 
> Sadly, the advertised Merthod#parameters
> (http://www.ruby-doc.org/core/classes/Method.html#M001075) does not seem to be
> available in the interpreter.

Its a feature of Ruby 1.9
Comment 5 Josef Reidinger 2012-10-29 09:46:18 UTC
martin - When I checking this feature, does YaST support somehow optional parameters or parameter overloading, so I can create more versions of same call?
Comment 6 Martin Vidner 2012-10-29 10:04:58 UTC
In YCP, function overloading only works for built-ins, not for user defined functions.

That's kind of stupid, having overloading implemented but keeping the user from using it in their APIs. We can fix that if we have a strong enough use case.
Comment 7 Josef Reidinger 2012-10-29 10:36:40 UTC
(In reply to comment #6)
> In YCP, function overloading only works for built-ins, not for user defined
> functions.
> 
> That's kind of stupid, having overloading implemented but keeping the user from
> using it in their APIs. We can fix that if we have a strong enough use case.

Well, this is one use case. Without it I cannot fix this bug, as it is hard to convert ruby optional parameters if ycp doesn't allow it
Comment 8 Josef Reidinger 2013-08-19 07:00:11 UTC
with current ruby-bindings and new way how to export ruby code to component system, issue is no longer valid.