-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
IllegalArgumentException: Could not find proxy for Lambda/ValDef combination in quotes #13922
Comments
In the original example it seems fishy to ignore the lambda symbol in case (_, List(arg: Term)) => This is supposed to be the owner of any definition within the lambda. The code should probably be case (meth, List(arg: Term)) =>
ValDef.let(meth, "v", arg) { v => |
Running the code with -- Error: tests/pos-macros/i13922/Test_2.scala:1:11 ----------------------------
1 |def test = optPrettyPrinter(Some("foo"))
| ^^^^^^^^^^^^^^^^
|Exception occurred while executing macro expansion.
|java.lang.AssertionError: assertion failed: Tree had an unexpected owner for val v
|Expected: method $anonfun (Test_2$package$._$_$$anonfun)
|But was: val macro (Test_2$package$._$macro)
|
|
|The code of the definition of val v is
|val v: java.lang.String = macroVal
|
|which was found in the code
|{
| val v: java.lang.String = macroVal
| val vv: java.lang.String = v
| scala.Predef.println("v=".+(vv.toString()))
|
| (vv: java.lang.String)
|}
|
|which has the AST representation
|Block(List(ValDef("v", Inferred(), Some(Ident("macroVal")))), Inlined(Some(TypeIdent("Macro_1$package$")), Nil, Block(List(ValDef("vv", Inferred(), Some(Inlined(None, Nil, Ident("v")))), Apply(Ident("println"), List(Apply(Select(Literal(StringConstant("v=")), "+"), List(Apply(Select(Ident("vv"), "toString"), Nil)))))), Typed(Ident("vv"), Inferred()))))
|
|
| at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
| at scala.quoted.runtime.impl.QuotesImpl$$anon$9.traverse(QuotesImpl.scala:2910)
| at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1640)
| at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1640)
| at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.fold$1(Trees.scala:1515)
| at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.apply(Trees.scala:1517)
| at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1548)
| at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1641)
| at scala.quoted.runtime.impl.QuotesImpl$$anon$9.traverse(QuotesImpl.scala:2913)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$.xCheckMacroOwners(QuotesImpl.scala:2914)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$.scala$quoted$runtime$impl$QuotesImpl$reflect$$$xCheckMacroedOwners(QuotesImpl.scala:2885)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$Lambda$.apply$$anonfun$22$$anonfun$1(QuotesImpl.scala:797)
| at dotty.tools.dotc.ast.tpd$.DefDef(tpd.scala:285)
| at dotty.tools.dotc.ast.tpd$.Closure(tpd.scala:120)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$Lambda$.apply$$anonfun$22(QuotesImpl.scala:797)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$.scala$quoted$runtime$impl$QuotesImpl$reflect$$$withDefaultPos(QuotesImpl.scala:2867)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$Lambda$.apply(QuotesImpl.scala:797)
| at scala.quoted.runtime.impl.QuotesImpl$reflect$Lambda$.apply(QuotesImpl.scala:795)
| at Macro_1$package$.optPrettyPrinterImpl(Macro_1.scala:32)
| at Macro_1$package$.inline$optPrettyPrinterImpl(Macro_1.scala:6)
|
| This location contains code that was inlined from Test_2.scala:1 |
The following is the correct fix case (meth, List(arg: Term)) =>
ValDef.let(meth, "v", arg) { v => but then we hit another issue with the owner of the quote in the '{
val vv = ${ v.asExprOf[T] }
println("v=" + vv.toString())
vv
- }.asTerm
+ }.asTerm.changeOwner(owner) To set the owner of the quote correctly from the start we need #13652 and would need to do given Quotes = owner.asQuotes
ValDef.let(m, "v", arg) { v =>
'{
val vv = ${ v.asExprOf[T] }
println("v=" + vv.toString())
vv
}.asTerm
}
|
This makes it possible to create `Expr`s with different owners to avoid a call to `changeOwner`. Closes scala#13922
For now |
This makes it possible to create `Expr`s with different owners to avoid a call to `changeOwner`. Closes scala#13922
This makes it possible to create `Expr`s with different owners to avoid a call to `changeOwner`. Closes scala#13922
This makes it possible to create `Expr`s with different owners to avoid a call to `changeOwner`. Closes scala#13922
This makes it possible to create `Expr`s with different owners to avoid a call to `changeOwner`. Closes scala#13922
This makes it possible to create `Expr`s with different owners to avoid a call to `changeOwner`. Closes scala#13922
This makes it possible to create `Expr`s with different owners to avoid a call to `changeOwner`. Closes scala#13922
This makes it possible to create `Expr`s with different owners to avoid a call to `changeOwner`. Closes scala#13922
This makes it possible to create `Expr`s with different owners to avoid a call to `changeOwner`. Closes scala#13922
This makes it possible to create `Expr`s with different owners to avoid a call to `changeOwner`. Closes scala#13922
This makes it possible to create `Expr`s with different owners to avoid a call to `changeOwner`. Closes scala#13922
This makes it possible to create `Expr`s with different owners to avoid a call to `changeOwner`. Closes scala#13922
Compiler version
3.1.2-RC1-bin-20211022-f7abd32-NIGHTLY-git-f7abd32
Minimized code
Output
(run-main-2) java.lang.IllegalArgumentException: Could not find proxy for val vv: String in List(val vv, method res0, module class rs$line$1$, module class repl$, module class ), encl = package repl, owners = package repl, package ; enclosures = package repl, package java.lang.IllegalArgumentException: Could not find proxy for val vv: String in List(val vv, method res0, module class rs$line$1$, module class repl$, module class ), encl = package repl, owners = package repl, package ; enclosures = package repl, package
Expectation
Details
The following is working fine, not mixing
'{ ... }
with tree constructed usingLambda
/ValDef
.Also coming back to macro
optPrettyPrinter
it can be fixed usingchangeOwner
.The importance of
changeOwner
should at least be documented on theLambda
factories, maybe always enforced.The text was updated successfully, but these errors were encountered: