-
Notifications
You must be signed in to change notification settings - Fork 20
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
Macro error when expanding partial function #19
Comments
This test generates this problematic raw = (() => {
val f: PartialFunction[Int,Int] = (({
class $anonfun extends scala.runtime.AbstractPartialFunction[Int,Int] with Serializable {
def <init>(): <$anon: Int => Int> = {
$anonfun.super.<init>();
()
};
final override def applyOrElse[A1 <: Int, B1 >: Int](x1: A1, default: A1 => B1): B1 = ((x1.asInstanceOf[Int]: Int): Int @unchecked) match {
case (x @ _) => x.+(1)
case (defaultCase$ @ _) => default.apply(x1)
};
final def isDefinedAt(x1: Int): Boolean = ((x1.asInstanceOf[Int]: Int): Int @unchecked) match {
case (x @ _) => true
case (defaultCase$ @ _) => false
}
};
new $anonfun()
}: PartialFunction[Int,Int]): PartialFunction[Int,Int]);
AsyncAwaitTest.await[Int].apply[(scala.concurrent.Future[Int], org.coroutines.AsyncAwaitTest.Cell[Int]), Int](scala.concurrent.Future.apply[Int](f.apply(2))(scala.concurrent.ExecutionContext.Implicits.global))(Predef.this.=:=.tpEquals[((scala.concurrent.Future[Int], org.coroutines.AsyncAwaitTest.Cell[Int]), Int)])
}) Canonicalization fails when going over
|
Can you extend traverser to correctly cover the other cases? |
Yes! I'm working on it in this branch. |
It is not the second case that is dropped by the quasiquotes. Rather, it is the default case, e.g.: case (defaultCase$ @ _) => default.apply(x1) For instance, see that this partial function: val f = {
case x: Int => x + 1
case x: String => x.length
}: PartialFunction[Any, Int] has the following values for List(case (x @ (_: scala.Int)) => x.+(1), case (x @ (_: scala.this.Predef.String)) => x.length())
List(case (x @ (_: Int)) => x.+(1), case (x @ (_: String)) => x.length()) Thus, we might want to stop canonicalization for the default cases. What do you think? |
No, that's not the problem. |
I think I'm misunderstanding your statement. The partial function case matches on the anonymous partial function. This call to traverse is caused by the ascription case, in which
t0 = ({
final <synthetic> class $anonfun extends scala.runtime.AbstractPartialFunction[Int,Int] with Serializable {
def <init>() = {
super.<init>();
()
};
final override def applyOrElse[A1 <: Int, B1 >: Int](x1: A1, default: scala.this.Function1[A1, B1]) = ((x1.asInstanceOf[Int]: Int): (x1.asInstanceOf[Int]: Int): @scala.unchecked) match {
case (x @ _) => x.+(1)
case (defaultCase$ @ _) => default.apply(x1)
};
final def isDefinedAt(x1: Int): Boolean = ((x1.asInstanceOf[Int]: Int): (x1.asInstanceOf[Int]: Int): @scala.unchecked) match {
case (x @ _) => true
case (defaultCase$ @ _) => false
}
};
new $anonfun()
}: PartialFunction[Int,Int]) However, |
Demo code: https://git.io/vrHmh
As recommended in #15, I'm porting some of the tests from Async into Coroutines. I translated this test and discovered a
NullPointerException
during compilation. A truncated SBT dump is at the bottom of this issue.I believe this may be related to @retronym's comment in #15. I will investigate this more soon; just wanted to go ahead and bring the issue up.
The text was updated successfully, but these errors were encountered: