Skip to content

Incorrect. recursive value error on non-recursive value when transparent inline capability type should be inferred #16116

Closed
@rssh

Description

@rssh

Compiler version

3.2.1-RC2

Minimized code

package x

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

trait CpsMonad[F[_]] {
  type Context
}

object CpsMonad {
  type Aux[F[_],C] = CpsMonad[F] { type Context = C } 
  given CpsMonad[Future] with {}
}

@experimental
object Test {

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

  transparent inline def cpsAsync[F[_]](using m:CpsMonad[F]) =
    new Test.InfernAsyncArg

  class InfernAsyncArg[F[_],C](using am:CpsMonad.Aux[F,C]) {
      def apply[A](expr: (CpsTransform[F], C) ?=> 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
     }

}

Both transparent and -cc options are needed to receive error.

Output

[info] Executing in batch mode. For better performance use sbt's shell
[info] compiling 1 Scala source to /Users/rssh/tests/dotty/cc-incorrect-recursive/target/scala-3.2.1-RC2/classes ...
[error] -- [E045] Cyclic Error: /Users/rssh/tests/dotty/cc-incorrect-recursive/src/main/scala/cps/CpsTransform.scala:34:14 
[error] 34 |     val fr = cpsAsync[Future] {
[error]    |              ^
[error]    |              Recursive value fr needs type
[error]    |----------------------------------------------------------------------------
[error]    | Explanation (enabled by `-explain`)
[error]    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]    | The definition of value fr is recursive and you need to specify its type.
[error]     ----------------------------------------------------------------------------
[error] Explanation
[error] ===========
[error] The definition of value fr is recursive and you need to specify its type.

Expectation

fr is not recursive, code should be compiled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions