Could not find proxy in macro #13571
-
This is a minimization of a larger macro that I'm constructing for inline def checked2[A](inline n: A): A =
${ checkedImpl2[A]('{n}) }
private def checkedImpl2[A](n: Expr[A])(using Quotes, Type[A]): Expr[A] =
import quotes.reflect.*
val tree: Term = n.asTerm
val acc = new TreeMap:
override def transformTerm(tree: Term)(owner: Symbol): Term =
tree match
case Apply(Select(x, "*"), List(y)) =>
'{
val xt = ${x.asExprOf[Long]}
xt
}.asTerm
case _ =>
super.transformTerm(tree)(owner)
acc.transformTerm(tree)(tree.symbol).asExprOf[A] On test code this compiles just fine:
But this fails test("border case") {
val u = 3L
checked2(List(1L, 2L).map { k =>
u * 2L
})
} And the latest code gives this error:
I'm not really sure where this comes from or how to fix it. any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Using the -- Error: tests/pos-macros/i13571/Test_2.scala:3:12 ----------------------------
3 | checked2(List(1L, 2L).map { k =>
| ^
|Exception occurred while executing macro expansion.
|java.lang.AssertionError: assertion failed: Tree had an unexpected owner for val xt
|Expected: method $anonfun (Test_2$package$._$_$$anonfun)
|But was: val macro (Test_2$package$._$macro)
|
|
|The code of the definition of val xt is
|val xt: scala.Long = u
|
|which was found in the code
|{
| val xt: scala.Long = u
|
| (xt: scala.Long)
|}
|
|which has the AST representation
|Block(Nil, Inlined(Some(TypeIdent("Macro_1$package$")), Nil, Block(List(ValDef("xt", Inferred(), Some(Inlined(None, Nil, Ident("u"))))), Typed(Ident("xt"), Inferred()))))
|
|
| at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
| at scala.quoted.runtime.impl.QuotesImpl$$anon$9.traverse(QuotesImpl.scala:2906)
| at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1656)
| at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1656)
| at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.fold$1(Trees.scala:1531)
| at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.apply(Trees.scala:1533)
| at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1564)
| at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1657)
| at scala.quoted.runtime.impl.QuotesImpl$$anon$9.traverse(QuotesImpl.scala:2909)
| at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1656)
| at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1656)
| at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1584)
| at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1537)
| at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1657)
| at scala.quoted.runtime.impl.QuotesImpl$$anon$9.traverse(QuotesImpl.scala:2909)
| at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1656)
| at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1656)
| at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1564)
| at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1657)
| at scala.quoted.runtime.impl.QuotesImpl$$anon$9.traverse(QuotesImpl.scala:2909)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$.xCheckMacroOwners(QuotesImpl.scala:2910)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$.scala$quoted$runtime$impl$QuotesImpl$reflect$$$xCheckMacroedOwners(QuotesImpl.scala:2872)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$DefDef$.copy(QuotesImpl.scala:266)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$DefDef$.copy(QuotesImpl.scala:265)
| at scala.quoted.Quotes$reflectModule$TreeMap.transformStatement(Quotes.scala:4479)
| at scala.quoted.Quotes$reflectModule$TreeMap.transformStatement$(Quotes.scala:4433)
| at Macro_1$package$$anon$1.transformStatement(Macro_1.scala:9)
| at scala.quoted.Quotes$reflectModule$TreeMap.transformStats$$anonfun$1(Quotes.scala:4573)
| at scala.collection.immutable.List.mapConserve(List.scala:472)
| at scala.quoted.Quotes$reflectModule$TreeMap.transformStats(Quotes.scala:4573)
| at scala.quoted.Quotes$reflectModule$TreeMap.transformStats$(Quotes.scala:4433)
| at Macro_1$package$$anon$1.transformStats(Macro_1.scala:9)
| at scala.quoted.Quotes$reflectModule$TreeMap.transformTerm(Quotes.scala:4517)
| at scala.quoted.Quotes$reflectModule$TreeMap.transformTerm$(Quotes.scala:4433)
| at Macro_1$package$$anon$1.transformTerm(Macro_1.scala:18)
| at scala.quoted.Quotes$reflectModule$TreeMap.transformTerm(Quotes.scala:4517)
| at scala.quoted.Quotes$reflectModule$TreeMap.transformTerm$(Quotes.scala:4433)
| at Macro_1$package$$anon$1.transformTerm(Macro_1.scala:18)
| at scala.quoted.Quotes$reflectModule$TreeMap.transformTerms$$anonfun$1(Quotes.scala:4579)
| at scala.collection.immutable.List.mapConserve(List.scala:472)
| at scala.quoted.Quotes$reflectModule$TreeMap.transformTerms(Quotes.scala:4579)
| at scala.quoted.Quotes$reflectModule$TreeMap.transformTerms$(Quotes.scala:4433)
| at Macro_1$package$$anon$1.transformTerms(Macro_1.scala:9)
| at scala.quoted.Quotes$reflectModule$TreeMap.transformTerm(Quotes.scala:4503)
| at scala.quoted.Quotes$reflectModule$TreeMap.transformTerm$(Quotes.scala:4433)
| at Macro_1$package$$anon$1.transformTerm(Macro_1.scala:18)
| at scala.quoted.Quotes$reflectModule$TreeMap.transformTerm(Quotes.scala:4533)
| at scala.quoted.Quotes$reflectModule$TreeMap.transformTerm$(Quotes.scala:4433)
| at Macro_1$package$$anon$1.transformTerm(Macro_1.scala:18)
| at Macro_1$package$.checkedImpl2(Macro_1.scala:19)
| at Macro_1$package$.inline$checkedImpl2(Macro_1.scala:6) The issue is that the quote is constructed using the owner of the The code can be fixed by changing the owner to the correct one '{
val xt = ${x.asExprOf[Long]}
xt
- }.asTerm
+ }.asTerm.changeOwner(owner) |
Beta Was this translation helpful? Give feedback.
-
Thanks, this helped me to get this solved: |
Beta Was this translation helpful? Give feedback.
-
Is this a bug, or is it something one would be expected to know? If so, how? |
Beta Was this translation helpful? Give feedback.
Using the
-Xcheck-macros
compiler flag we get