Skip to content
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

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

Closed
rssh opened this issue Sep 27, 2022 · 1 comment · Fixed by #16195
Labels
area:typer cc-experiment Intended to be merged with cc-experiment branch on origin itype:bug
Milestone

Comments

@rssh
Copy link
Contributor

rssh commented Sep 27, 2022

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.

@rssh rssh added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 27, 2022
@rssh
Copy link
Contributor Author

rssh commented Sep 27, 2022

Minimized a little`:

package x

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


@experimental
object Test {

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

  transparent inline def cpsAsync[F[_]] =
    new Test.InfernAsyncArg

  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
     }

}

@dwijnand dwijnand added cc-experiment Intended to be merged with cc-experiment branch on origin area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 30, 2022
odersky added a commit to dotty-staging/dotty that referenced this issue Oct 16, 2022
little-inferno pushed a commit to little-inferno/dotty that referenced this issue Jan 25, 2023
@Kordyjan Kordyjan added this to the 3.3.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typer cc-experiment Intended to be merged with cc-experiment branch on origin itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants