weirdness in typechecking call on overloaded java method

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

weirdness in typechecking call on overloaded java method

Jason Kinzer
Hi,

I've stumbled upon a typing issue I'm at a loss to explain. Following is a minimal test case:

---------------------------------------------
// ScalaMenuTest.scala
object ScalaMenuTest {
  def main(args: Array[String]): Unit = {
    val v = new javax.swing.JMenu()
    v.add(new javax.swing.JMenuItem())
    //v.add(new java.awt.PopupMenu());
  }
}

//==> compiling with scalac2 results in
//
// found   : javax.swing.JMenuItem
// required: java.awt.PopupMenu
//    v.add(new javax.swing.JMenuItem())
//          ^
//one error found
---------------------------------------------

As a sanity check, here is the equivalent Java code:

---------------------------------------------
// JavaMenuTest.java

class JavaMenuTest {
  public static void main(String[] args) {
    javax.swing.JMenu v = new javax.swing.JMenu();
    v.add(new javax.swing.JMenuItem());
   //v.add(new java.awt.PopupMenu());
  }
}
---------------------------------------------

I'd greatly appreciate if someone could verify; perhaps it's a environment-related issue on my end?? If not, is it perhaps a compiler bug?
What I find truly bizarre is that if the call adding a PopupMenu is uncommented, it then typechecks just fine.

Many thanks,
Jason
Reply | Threaded
Open this post in threaded view
|

Re: weirdness in typechecking call on overloaded java method

Lex Spoon
"Jason Kinzer" <[hidden email]> writes:

> I've stumbled upon a typing issue I'm at a loss to explain. Following is a
> minimal test case:
>
> ---------------------------------------------
> // ScalaMenuTest.scala
> object ScalaMenuTest {
>   def main(args: Array[String]): Unit = {
>     val v = new javax.swing.JMenu()
>     v.add(new javax.swing.JMenuItem())
>     //v.add(new java.awt.PopupMenu());
>   }
> }
>
> //==> compiling with scalac2 results in
> //
> // found   : javax.swing.JMenuItem
> // required: java.awt.PopupMenu
> //    v.add(new javax.swing.JMenuItem())
> //          ^
> //one error found
> ---------------------------------------------

There have been problems like this, but your example compiles for
me using version 2.0.5843 and 2.0.5774 .  Can you check your
version (scalac -version), and upgrade if it is older than these?

Otherwise, maybe it is environmental.  I am using a 1.5 Sun SDK.

-Lex

Reply | Threaded
Open this post in threaded view
|

Re: weirdness in typechecking call on overloaded java method

Jason Kinzer
Lex,

It was indeed an older version of the compiler.

Thanks for the reply & also thanks to Martin Sandin for passing on Sean's workaround (simply assign a dummy result to obtain the correct overload) and Martin Odersky for mentioning that the bug had already been fixed locally. I greatly appreciate the responses.

Jason

On 27 Feb 2006 11:10:30 +0100, Lex Spoon <[hidden email]> wrote:
"Jason Kinzer" <[hidden email]> writes:
> I've stumbled upon a typing issue I'm at a loss to explain. Following is a
> minimal test case:
>
> ---------------------------------------------

> // ScalaMenuTest.scala
> object ScalaMenuTest {
>   def main(args: Array[String]): Unit = {
>     val v = new javax.swing.JMenu()
>     v.add (new javax.swing.JMenuItem())
>     //v.add(new java.awt.PopupMenu());
>   }
> }
>
> //==> compiling with scalac2 results in
> //
> // found   : javax.swing.JMenuItem
> // required: java.awt.PopupMenu
> //    v.add(new javax.swing.JMenuItem())
> //          ^
> //one error found
> ---------------------------------------------

There have been problems like this, but your example compiles for
me using version 2.0.5843 and 2.0.5774 .  Can you check your
version (scalac -version), and upgrade if it is older than these?

Otherwise, maybe it is environmental.  I am using a 1.5 Sun SDK.

-Lex