Skip to content

Compiler crash with -Ycc when using capacity passed via intermediate inline function #16095

Closed
@rssh

Description

@rssh

Compiler version

3.2.1-RC2

-Ycc flag should be enabled.

Minimized code

package x

import scala.annotation.*
import scala.concurrent.*

@capability
class CpsTransform[F[_]] {
     def await[T](ft: F[T]): { this } T = ???
}

inline def cpsAsync[F[_]] =
  Test.InfernAsyncArg
object Test {

  class InfernAsyncArg[F[_]] {
      def apply[A](expr: CpsTransform[F] ?=> A): F[A] = ???
  }

  def asyncPlus[F[_]](a:Int, b:F[Int])(using cps: CpsTransform[F]): { cps } Int =
    a + cps.await(b)

  def testExample1Future(): Unit =
     val fr = cpsAsync[Future] {
        val y = asyncPlus(1,Future successful 2)
        y+1
     }
     val r = Await.result(fr)
     assert(r == Success(3))

}

Output (click arrow to expand)

[info] exception occurred while compiling /Users/rssh/tests/dotty/cc-crash1/src/main/scala/cps/CpsTransform.scala
scala.MatchError: TypeApply(Ident(cpsAsync),List(Ident(Future))) (of class dotty.tools.dotc.ast.Trees$TypeApply) while compiling /Users/rssh/tests/dotty/cc-crash1/src/main/scala/cps/CpsTransform.scala
[error] ## Exception when compiling 1 sources to /Users/rssh/tests/dotty/cc-crash1/target/scala-3.2.1-RC2/classes
[error] scala.MatchError: TypeApply(Ident(cpsAsync),List(Ident(Future))) (of class dotty.tools.dotc.ast.Trees$TypeApply)
[error] dotty.tools.dotc.typer.Typer.newExpr$1(Typer.scala:4033)
[error] dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4061)
[error] dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3431)
[error] dotty.tools.dotc.typer.Typer.tryApply$1(Typer.scala:3270)
[error] dotty.tools.dotc.typer.Typer.tryInsertApplyOrImplicit$$anonfun$2(Typer.scala:3288)
[error] dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3194)
[error] dotty.tools.dotc.typer.Typer.tryInsertApplyOrImplicit(Typer.scala:3295)
[error] dotty.tools.dotc.typer.Typer.adaptToArgs$1(Typer.scala:3523)
[error] dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4076)
[error] dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3431)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3050)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3054)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3170)
[error] dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:910)
[error] dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1052)
[error] dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:327)
[error] dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:121)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2920)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2983)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3050)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3054)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3170)
[error] dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1619)
[error] dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1609)
[error] dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1619)
[error] dotty.tools.dotc.typer.Namer.typedAheadRhs$1$$anonfun$1(Namer.scala:1871)
[error] dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:249)
[error] dotty.tools.dotc.typer.Namer.typedAheadRhs$1(Namer.scala:1871)
[error] dotty.tool

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions