Closed
Description
Compiler version
3.1.1-RC1
Minimized code
-Xcheck-macros should be in compiler flags.
file M.scala
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()
}
file X.scala:
package x
object Main:
def main(args: Array[String]):Unit =
Macro.genOp(10)
Output
[info] welcome to sbt 1.5.5 (Homebrew Java 17)
[info] loading global plugins from /Users/rssh/.sbt/1.0/plugins
[info] loading project definition from /Users/rssh/tests/dotty/restricted-correct-scope/project
[info] loading settings for project root from build.sbt ...
[info] set current project to test (in build file:/Users/rssh/tests/dotty/restricted-correct-scope/)
[info] Executing in batch mode. For better performance use sbt's shell
[info] compiling 2 Scala sources to /Users/rssh/tests/dotty/restricted-correct-scope/target/scala-3.1.1-RC1/classes ...
[error] -- Error: /Users/rssh/tests/dotty/restricted-correct-scope/src/main/scala/x/X.scala:6:17
[error] 6 | Macro.genOp(10)
[error] | ^^^^^^^^^^^^^^^
[error] |Exception occurred while executing macro expansion.
[error] |scala.quoted.runtime.impl.ScopeException: Expression created in a splice was used outside of that splice.
[error] |Created in: src/main/scala/x/M.scala:16 at column 9
[error] |Used in: src/main/scala/x/M.scala:20 at column 13
[error] |Expr: x
[error] |
[error] |
[error] |Creation stack:
[error] | src/main/scala/x/M.scala:16 at column 9
[error] | /Users/rssh/tests/dotty/restricted-correct-scope/src/main/scala/x/M.scala:7 at column 42
[error] |
[error] |
[error] |Use stack:
[error] | src/main/scala/x/M.scala:20 at column 13
[error] | /Users/rssh/tests/dotty/restricted-correct-scope/src/main/scala/x/M.scala:7 at column 42
[error] |
[error] |
[error] | at scala.quoted.runtime.impl.ScopeException$.checkInCorrectScope(ScopeException.scala:35)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$.quotedExprToTree(PickledQuotes.scala:43)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:82)
[error] | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1430)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:106)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:96)
[error] | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1396)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:106)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$.spliceTerms(PickledQuotes.scala:121)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$.unpickleTerm(PickledQuotes.scala:60)
[error] | at scala.quoted.runtime.impl.QuotesImpl.unpickleExpr(QuotesImpl.scala:2973)
[error] | at x.Macro$.secondOp$1(M.scala:20)
[error] | at x.Macro$.firstOp$1$$anonfun$1(M.scala:16)
[error] | at x.Macro$.firstOp$1$$anonfun$adapted$1(M.scala:16)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:81)
[error] | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1430)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:106)
[error] | at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1410)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$$anon$1.transform(PickledQuotes.scala:106)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$.spliceTerms(PickledQuotes.scala:121)
[error] | at dotty.tools.dotc.quoted.PickledQuotes$.unpickleTerm(PickledQuotes.scala:60)
[error] | at scala.quoted.runtime.impl.QuotesImpl.unpickleExpr(QuotesImpl.scala:2973)
[error] | at x.Macro$.firstOp$1(M.scala:16)
[error] | at x.Macro$.genOpImpl(M.scala:23)
[error] |
[error] | This location contains code that was inlined from X.scala:6
[error] one error found
[error] one error found
Expectation
should be compiled
Metadata
Metadata
Assignees
Labels
No labels