Skip to content

Inline implicit methods with lambdas cause AssertionError across files #5793

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
guyde2011 opened this issue Jan 25, 2019 · 0 comments · Fixed by #9143
Closed

Inline implicit methods with lambdas cause AssertionError across files #5793

guyde2011 opened this issue Jan 25, 2019 · 0 comments · Fixed by #9143

Comments

@guyde2011
Copy link

If you use in implicit inline method for instance generation, and you return an anonymous instance, which has a lambda in one of its methods implementation, then an assertion error is thrown.

Example:

Exec.scala

object exec{
  trait Runner[T]{
    def run(t: T): Unit
  }
  object Runner{
    def run[T: Runner](t: T): Unit = implicitly[Runner[T]].run(t) 
    implicit inline def runImplicitly[T]: Runner[T] = new {
      def run(t: T) = List(()).map(x => x).head // <<<
    }
  }  
}

Main.scala

object Main{
  def main(args: Array[String]): Unit = {
    import exec._
    Runner.run(Some(5))
  }
}

And it crashes with:

[error] Total time: 1 s, completed 15:17:31 25/01/2019
java.lang.AssertionError: assertion failed: private method $anonfun in object Main in C:\vscode\dotty\crash\main\src\main\scala\Main.scala accessed from method run in C:\vscode\dotty\crash\main\src\main\scala\Exec.scala while compiling C:\vscode\dotty\crash\main\src\main\scala\Exec.scala, C:\vscode\dotty\crash\main\src\main\scala\Main.scala

If we were to change

  object Runner{
    def run[T: Runner](t: T): Unit = implicitly[Runner[T]].run(t) 
    implicit inline def runImplicitly[T]: Runner[T] = new {
      def run(t: T) = List(()).map(x => x).head // <<<
    }
  }  

to

  object Runner{
    val mapping = (x: Unit) => x
    def run[T: Runner](t: T): Unit = implicitly[Runner[T]].run(t) 
    implicit inline def runImplicitly[T]: Runner[T] = new {
      def run(t: T) = List(()).map(mapping).head // <<<
    }
  }  

It works.

It works as well if we move the two sources to the same file.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jun 9, 2020
@nicolasstucki nicolasstucki linked a pull request Jun 9, 2020 that will close this issue
anatoliykmetyuk added a commit that referenced this issue Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants