scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.79k stars 1.04k forks source link

Failed unification of arguments, dependent from given arguments. #8045

Closed rssh closed 4 years ago

rssh commented 4 years ago

minimized code

package cps3

import scala.quoted._

object Test

  def run(given qctx: QuoteContext)(
                                    cases: List[qctx.tasty.CaseDef],
                                    ): Int =
     import qctx.tasty.{_, given}
     val l =  '{  ${makeExpr(cases)}+1  }
     ???

  def makeExpr(given qctx: QuoteContext)(
                                        caseDefs: List[qctx.tasty.CaseDef],
                                        ):Expr[Int] =
     ???
```scala ... [error] -- [E007] Type Mismatch Error: /Users/rssh/work/oss/dotty-cps/dotty-cps/src/test/scala/cps/cbs2/TestCompileTryTransform.scala:12:29 [error] 12 | val l = '{ ${makeExpr(cases)}+1 } [error] | ^^^^^ [error] | Found: (cases : List[qctx.tasty.CaseDef]) [error] | Required: List[evidence$1.tasty.CaseDef] [error] one error found ```

expectation

should compiled.

nicolasstucki commented 4 years ago

Minimized to

import scala.quoted._
object Test
  def run(given qctx: QuoteContext)(tree: qctx.tasty.Tree): Unit =
    '{  ${(given qctx2) => makeExpr(given qctx2)(tree) } + 1  }
  def makeExpr(given qctx: QuoteContext)(tree: qctx.tasty.Tree): Expr[Int] = ???

The issue is that currently there is no relation between the context given to the quote and the one provided by the splice.

nicolasstucki commented 4 years ago

Workarounds

import scala.quoted._
object Test
  def run(given qctx: QuoteContext)(tree: qctx.tasty.Tree): Unit =
    val expr = makeExpr(tree)
    '{  $expr + 1  }
  def makeExpr(given qctx: QuoteContext)(tree: qctx.tasty.Tree): Expr[Int] = ???
import scala.quoted._
object Test
  def run(given qctx: QuoteContext)(tree: qctx.tasty.Tree): Unit =
    '{  ${(given qctx2: QuoteContext) => makeExpr(given qctx)(tree) } + 1  }
  def makeExpr(given qctx: QuoteContext)(tree: qctx.tasty.Tree): Expr[Int] = ???