Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/src/scala/quoted/runtime/impl/ScopeException.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ object ScopeException:
|
|Use stack:
|${currentScope.stack.mkString("\t", "\n\t", "\n")}
|
|Hint: A common reason for this to happen is when a `def` that creates a `'{...}`
| captures an outer instance of `Quotes`. If this `def` is called in a splice
| it will not track the `Quotes` provided by that particular splice.
| To fix it add a `given Quotes` to this `def`.
""".stripMargin)
23 changes: 23 additions & 0 deletions tests/neg-macros/i14137/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package x

import scala.quoted._

object Macro:

inline def genOp(inline f:Int): Int = ${
genOpImpl('f)
}

def genOpImpl(f: Expr[Int])(using Quotes): Expr[Int] = {

def firstOp(): Expr[Int] =
'{
var x=1
${secondOp('x,f)}
}

def secondOp(x:Expr[Int], y:Expr[Int]): Expr[Int] =
'{ $x + $y }

firstOp()
}
6 changes: 6 additions & 0 deletions tests/neg-macros/i14137/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package x

object Main:

def main(args: Array[String]):Unit =
Macro.genOp(10) // error
23 changes: 23 additions & 0 deletions tests/pos-macros/i14137/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package x

import scala.quoted._

object Macro:

inline def genOp(inline f:Int): Int = ${
genOpImpl('f)
}

def genOpImpl(f: Expr[Int])(using Quotes): Expr[Int] = {

def firstOp()(using Quotes): Expr[Int] =
'{
var x=1
${secondOp('x,f)}
}

def secondOp(x:Expr[Int], y:Expr[Int])(using Quotes): Expr[Int] =
'{ $x + $y }

firstOp()
}
6 changes: 6 additions & 0 deletions tests/pos-macros/i14137/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package x

object Main:

def main(args: Array[String]):Unit =
Macro.genOp(10)