Skip to content

NoSuchElementException in typing anonymous function with quotes #4380

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

Closed
biboudis opened this issue Apr 25, 2018 · 3 comments
Closed

NoSuchElementException in typing anonymous function with quotes #4380

biboudis opened this issue Apr 25, 2018 · 3 comments

Comments

@biboudis
Copy link
Contributor

biboudis commented Apr 25, 2018

The problem doesn't appear when I remove quotes or the new Producer or the val adv in line 17 or try to type the step method outside the new Producer🤔. However, it can be minimized further I think.

import scala.quoted._

object Test {

  trait Producer[A] { self =>
    def step(k: (A => Expr[Unit])): Expr[Unit]
  }

  trait Foo[A]
  case class Bar[A, B](producer: Producer[B], nestedf: B => Expr[Unit]) extends Foo[A]

  def meth[A](stream: Foo[Expr[A]]): Producer[Expr[A]] = {
    stream match {
      case Bar(producer, nestedf) => {
        new Producer[Expr[A]] {
          def step(k: Expr[A] => Expr[Unit]): Expr[Unit] = '{
            val adv: Unit => Unit = { _ => ~producer.step((el) => nestedf(el))}
          }
        }
      }
    }
  }
}
java.util.NoSuchElementException: key not found: method $anonfun while traversing nestedf
java.util.NoSuchElementException: key not found: method $anonfun while traversing nestedf.apply
java.util.NoSuchElementException: key not found: method $anonfun while traversing nestedf.apply(el)
java.util.NoSuchElementException: key not found: method $anonfun while traversing nestedf.apply(el).asInstanceOf
java.util.NoSuchElementException: key not found: method $anonfun while traversing nestedf.apply(el).asInstanceOf[scala.quoted.Expr]
java.util.NoSuchElementException: key not found: method $anonfun while traversing def $anonfun(el: Object): scala.quoted.Expr =
  nestedf.apply(el).asInstanceOf[scala.quoted.Expr]
java.util.NoSuchElementException: key not found: method $anonfun while traversing {
  def $anonfun(el: Object): scala.quoted.Expr =
    nestedf.apply(el).asInstanceOf[scala.quoted.Expr]
  closure($anonfun:Function1)
}
.....
Exception in thread "main" java.util.NoSuchElementException: key not found: method $anonfun
	at scala.collection.MapLike.default(MapLike.scala:232)
	at scala.collection.MapLike.default$(MapLike.scala:231)
	at scala.collection.AbstractMap.default(Map.scala:59)
	at scala.collection.MapLike.apply(MapLike.scala:141)
	at scala.collection.MapLike.apply$(MapLike.scala:140)
	at scala.collection.AbstractMap.apply(Map.scala:59)
	at dotty.tools.dotc.transform.LambdaLift$Lifter.narrowLiftedOwner(LambdaLift.scala:99)
	at .....
@nicolasstucki
Copy link
Contributor

There is a wrong owner for an anonymous function after ReifyQuotes. -Ycheck:all shows which one.

@nicolasstucki nicolasstucki self-assigned this Apr 26, 2018
@nicolasstucki
Copy link
Contributor

Minimized to

import scala.quoted._

object Test {
  def step(k: (String => Expr[Unit])): Expr[Unit] = '()
  def meth(): Unit = '{
    (i: Int) => ~step(el => '() )
  }
}

fails with -Ycheck:all

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 26, 2018
Implementation for optimization bf13d5b needs to be revisited.
@nicolasstucki
Copy link
Contributor

The optimization done in bf13d5b broke some owners.

nicolasstucki added a commit that referenced this issue Apr 27, 2018
 Fix #4380: Revert optimization that breaks owners
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants