Skip to content

inline chain corrupts type along the way #11894

Closed
@japgolly

Description

@japgolly

Compiler version

3.0.0-RC2-bin-20210325-eeb8340-NIGHTLY

Minimized code

object CallbackTo {
  extension [A](self: CallbackTo[Option[A]]) {
    inline def asOption: Option[A] =
      self.toScalaFn()
  }
}

final class CallbackTo[A] (val x: List[A]) {

  inline def runNow(): A =
    x.head

  inline def toScalaFn: () => A =
    () => runNow()

  def map[B](f: A => B): CallbackTo[B] =
    ???

  def toOption: Option[A] = {
    val x = map[Option[A]](Some(_))
    val y = x: CallbackTo[Option[A]] // ok: type is what we expect
    y.asOption // error
  }
}

Output

22 |    y.asCallbackOption // error
   |    ^^^^^^^^^^^^^^^^^^
   |    Found:    Option[Option[A]]
   |    Required: Option[A]
   | This location contains code that was inlined from x.scala:21

Expectation

It should compile. There are 3 inlines in this snippet and removing any of them makes this compile again.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions