unusual type conversion in invoke

Per Bothner per@bothner.com
Thu Apr 3 18:11:00 GMT 2003


Vladimir Tsichevski wrote:
> Hi all,
> 
> just discovered an unusual time conversion kawa implicitly does when 
> looking for
> appropriate method to invoke.
> 
> the following line:
> 
> (invoke 'abcd 'indexOf 10)
> 
> compiles to:
> 
> "abcd".indexOf("10");
> 
> i.e. the number 10 becomes the string "10".
> 
> a workaround is to explicitly defining the type of constant:
> 
> (invoke 'abcd 'indexOf (as <int> 10))
> 
> but I cannot imagine the situation when such implicitly conversion might 
> be useful :-(

What's happening is that String.indexof(String) is considered
"definitely applicable" (any object can be converted to a
string using toString), while String.indexOf(int) applied
to a gnu.math.IntNum is "conditionally applicable" (since
the runtime value may be too large.  And the method selection
code prefers methods that are definitely applicable.

One could argue about whether the toString conversion should
be automatic, but it should certainly be lower priority.
We might want some types (as least Scheme strings) to be
automatically converted to Java Strings.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/




More information about the Kawa mailing list