bug-kawa
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-kawa] [bug #40253] problems with boolean parameter in overloaded me


From: Per Bothner
Subject: [Bug-kawa] [bug #40253] problems with boolean parameter in overloaded methods
Date: Sun, 13 Oct 2013 06:50:20 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.66 Safari/537.36

URL:
  <http://savannah.gnu.org/bugs/?40253>

                 Summary: problems with boolean parameter in overloaded
methods
                 Project: Kawa
            Submitted by: bothner
            Submitted on: Sun 13 Oct 2013 06:50:20 AM GMT
                Category: Type declaration and inference
                Severity: 3 - Normal
              Item Group: Unexpected result
                  Status: None
                 Privacy: Public
             Assigned to: bothner
             Open/Closed: Open
         Discussion Lock: Any

    _______________________________________________________

Details:

Notwithstanding bug #39047, there are still problems with overloaded methods
with a boolean parameter.

(1) Consider Java file:
public class bar {
      public void ff(java.util.List x) { System.out.println("s/x: "+x);
System.out.flush();}
    public void ff(boolean x) { System.out.println("b/x: "+x);
System.out.flush();}
}
and Scheme file:
(define bb (bar))
(define x::integer 12)
(bb:ff x)

This doesn't work.  The java.util.List methods is preferred as "possibly
applicable", which fails at run-time, even though the boolean method should
work.

Note it works if we comment out the List method, but we get a compile-time
warning.

(2) Overload resolution at compile-time vs run-time is inconsistent. 
Consider:

(define wtr
   (java.io.PrintWriter
       (java.io.OutputStreamWriter (java.lang.System:.out) "UTF-8")))
(define (print-it)
    (wtr:println "PRINT ME"))
(print-it)
((->java.io.PrintWriter wtr):flush)

This works if loaded in whole-module mode, but if we use --script (or -f) the
boolean method is chosen, because it is earlier in the sort order when
building a GenericProc.

A possible approach is to consider a method:
  foo(boolean x)
as if it where two methods:
  foo(boolean_strict x) // requires argument to be a boolean
  foo(convert_to_boolean x) // convert argument to boolean
The former would be very specific and applicable only to booleans, just as in
Java.  The latter is very non-specific and applicable to all arguments - it
would be views as "less specific" than Object.





    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?40253>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]