-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regression: Signatures of specialization interacts adversely with javac #5976
Comments
Imported From: https://issues.scala-lang.org/browse/SI-5976?orig=1 |
@paulp said: For the lucky assignee whose time has no value to reporter, here they are: https://groups.google.com/group/scala-internals/browse_thread/thread/5d28b67550491fc6 |
@viktorklang said (edited on Jun 25, 2012 4:17:44 PM UTC): |
@paulp said: Meanwhile the other of us thinks reporting issues via mailing list chatter is good enough, and then when imposed upon to open tickets like everyone else, somehow has the nerve to completely omit the products of said morning's work. If this is your usual mode of operation, your time must be valuable indeed. |
@viktorklang said: Summary: I am very sorry I forgot to add the link to the discussion, it was not an intentional omission, I respect you and your work a lot and I hope that this misunderstanding has been cleared up. |
@paulp said: |
@adriaanm said: |
@axel22 said (edited on Jun 27, 2012 1:30:18 PM UTC): Scala: import scala.runtime.BoxedUnit
object japi {
trait MyFunction[-T, +R] {
def apply(t: T): R
}
@deprecated("Do not use this directly, use subclasses of this", "2.0")
class UnitFunctionBridge[-T] extends MyFunction[T, BoxedUnit] {
override final def apply(t: T): BoxedUnit = {
internal(t)
BoxedUnit.UNIT
}
protected def internal(result: T): Unit = ()
}
}
abstract class Foreach[-T] extends japi.UnitFunctionBridge[T] {
override final def internal(t: T): Unit = each(t)
/**
* This method will be invoked once when/if a Future that this callback is registered on
* becomes successfully completed
*/
@throws(classOf[Throwable])
def each(result: T): Unit
} Java: public class Test {
public void mustBeAbleToForeachAFuture() throws Throwable {
new Foreach<String>() {
public void each(String future) {
}
};
}
} Result after running: java.lang.NoSuchMethodException: Test.main([Ljava.lang.String;)
at java.lang.Class.getMethod(Class.java:1622)
at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:67)
at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:139)
at scala.tools.nsc.CommonRunner$class.run(ObjectRunner.scala:28)
at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:45)
at scala.tools.nsc.CommonRunner$class.runAndCatch(ObjectRunner.scala:35)
at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:45)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:70)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:92)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:101)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala) I would reassign this. |
@gkossakowski said: |
@gkossakowski said: |
@paulp said: |
@viktorklang said: |
@axel22 said: |
@gkossakowski said: |
@adriaanm said: import scala.runtime.BoxedUnit
object japi {
@deprecated("Do not use this directly, use subclasses of this", "2.0")
class UnitFunctionBridge[-T] extends (T ⇒ BoxedUnit) {
override final def apply(t: T): BoxedUnit = {
internal(t)
BoxedUnit.UNIT
}
protected def internal(result: T): Unit = ()
}
}
abstract class Foreach[-T] extends japi.UnitFunctionBridge[T] {
override final def internal(t: T): Unit = each(t)
/**
* This method will be invoked once when/if a Future that this callback is registered on
* becomes successfully completed
*/
@throws(classOf[Throwable])
def each(result: T): Unit
}
class Future[T] { def foreach[U](f: T => U): U = ??? } // Test.java public class Test {
public void mustBeAbleToForeachAFuture(Future<String> f) throws Throwable {
f.foreach(new Foreach<String>() {
public void each(String future) {
}
});
}
} |
@paulp said: class Future[+T](val result: T) {
def foreach(x: Foreach[T]): Unit = x each result
} |
@gkossakowski said: // t5976.scala
import scala.runtime.BoxedUnit
import scala.runtime.AbstractFunction1
object japi {
@deprecated("Do not use this directly, use subclasses of this", "2.0")
class UnitFunctionBridge[-T] extends AbstractFunction1[T, BoxedUnit] {
override final def apply(t: T): BoxedUnit = {
internal(t)
BoxedUnit.UNIT
}
protected def internal(result: T): Unit = ()
}
}
abstract class Foreach[-T] extends japi.UnitFunctionBridge[T] {
override final def internal(t: T): Unit = each(t)
/**
* This method will be invoked once when/if a Future that this callback is registered on
* becomes successfully completed
*/
@throws(classOf[Throwable])
def each(result: T): Unit
}
class Future[T] { def foreach[U](f: T => U): U = sys.error("foo") } and: // Test.java
public class Test {
public void mustBeAbleToForeachAFuture(Future<String> f) throws Throwable {
f.foreach(new Foreach<String>() {
public void each(String future) {
}
});
}
} Closing this as Not a bug because I don't believe there's actual bug here and there's an easy work-around present. Maybe we should generate bridge methods in UnitFunctionBridge but I'm not sure. |
@viktorklang said: |
@paulp said: |
@gkossakowski said: I think it might be hard to satisfy javac. I don't know all issues related to bridge methods and how javac treats them so more investigation would be needed. However, I just wanted to say that I don't think this is critical for 2.10.0 release. |
@gkossakowski said: |
@paulp said: |
@gkossakowski said:
Stay tuned. |
@paulp said: I do not think this is a matter of bridges, but of generating the right signatures. I will point against at #3452 if you're looking into this: it is subtle. |
@SethTisue said: |
@gkossakowski said: It contains truly minimized test-case. I'll assign both tickets to Alex as this is purely specialization problem. |
@adriaanm said: |
@adriaanm said: |
The following code worked flawlessly on 2.9:
And then from Java:
However, using Scala 2.10-M4 javac spits this in mah face:
This steps around it... But I think it has a certain kind of smell:
The text was updated successfully, but these errors were encountered: