This page is no longer maintained — Please continue to the home page at www.scala-lang.org

traits, generics, java interop + @specialized

1 reply
Vladimir Kirichenko
Joined: 2009-02-19,
User offline. Last seen 42 years 45 weeks ago.

Here the thing I've found during exploration of Java complaining on
generics in methods generated for specialization.
The problem also found with method generaited for trait implementation.

An example:

Scala:

trait Test[A] {
def m( a: A ): A
def specified(a:A):A = a
}

abstract class T2[A] extends Test[A]

Java:

public class JTest extends T2 {
public A m( A a ) {
return a;
}
}

java compiler (-Xlint:unckecked) complains about:

specified(java.lang.Object) in T2 implements specified(A) in Test;
return type requires unchecked conversion
found : java.lang.Object
required: A

JD Java Decompiler shows that generated method is not generic:

public abstract interface Test extends ScalaObject
{
public abstract A m(A paramA);

public abstract A specified(A paramA);
}

public abstract class T2
implements Test
, ScalaObject
{
public Object specified(Object a)
{
return Test.class.specified(this, a); }
public T2() { Test.class.$init$(this); }

}

public class JTest extends T2
{
public A m(A a)
{
return a;
}
}

> scalac -version
Scala compiler version 2.8.0.r22036-b20100526020129 -- Copyright
2002-2010, LAMP/EPFL

Ticket: https://lampsvn.epfl.ch/trac/scala/ticket/3486

Iulian Dragos 2
Joined: 2009-02-10,
User offline. Last seen 42 years 45 weeks ago.
Re: traits, generics, java interop + @specialized
This is indeed a bug, but has nothing to do with @specialized (or if it does, please be more specific).
Mixed in methods seem to lack their Java signature. I updated the ticket, thanks for reporting!
iulian

On Wed, May 26, 2010 at 7:03 PM, Vladimir Kirichenko <vladimir.kirichenko@gmail.com> wrote:
Here the thing I've found during exploration of Java complaining on
generics in methods generated for specialization.
The problem also found with method generaited for trait implementation.

An example:

Scala:

trait Test[A] {
       def m( a: A ): A
       def specified(a:A):A = a
}

abstract class T2[A] extends Test[A]

Java:

public class JTest<A> extends T2<A> {
       public A m( A a ) {
               return a;
       }
}

java compiler (-Xlint:unckecked) complains about:

specified(java.lang.Object) in T2 implements specified(A) in Test;
return type requires unchecked conversion
found   : java.lang.Object
required: A


JD Java Decompiler shows that generated method is not generic:

public abstract interface Test<A> extends ScalaObject
{
 public abstract A m(A paramA);

 public abstract A specified(A paramA);
}


public abstract class T2<A>
 implements Test<A>, ScalaObject
{
 public Object specified(Object a)
 {
   return Test.class.specified(this, a); }
 public T2() { Test.class.$init$(this); }

}

public class JTest<A> extends T2<A>
{
 public A m(A a)
 {
   return a;
 }
}

> scalac -version
Scala compiler version 2.8.0.r22036-b20100526020129 -- Copyright
2002-2010, LAMP/EPFL

Ticket: https://lampsvn.epfl.ch/trac/scala/ticket/3486

--
Best Regards,
Vladimir Kirichenko



--
« Je déteste la montagne, ça cache le paysage »
Alphonse Allais

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland