Closed
Description
Compiler version
3.3.0, 3.3.2-RC1-bin-SNAPSHOT as today
Minimized code
file X.scala:
package x
import scala.quoted.*
class IntRef(var x: Int) {
def plus(y:Int): Int = ???
}
object X {
inline def test(ref:IntRef):Int = ${ testImpl('ref) }
def testImpl(ref:Expr[IntRef])(using Quotes):Expr[Int] = {
import quotes.reflect.*
val fun0 = Select.unique(ref.asTerm,"plus")
val fun1 = Block(List(Assign(Select.unique(ref.asTerm,"x"),Literal(IntConstant(1)))),fun0)
val r = Apply(fun1,List(Literal(IntConstant(2))))
r.asExprOf[Int]
}
}
fille Main.scala:
package x
object Main {
val ref = IntRef(0)
X.test(ref)
}
Output
info] compiling 2 Scala sources to /Users/rssh/tests/dotty/bad-apply/target/scala-3.3.2-RC1-bin-SNAPSHOT/classes ...
[error] -- Error: /Users/rssh/tests/dotty/bad-apply/src/main/scala/x/Main.scala:7:8 ----
[error] 7 | X.test(ref)
[error] | ^^^^^^^^^^^
[error] |Exception occurred while executing macro expansion.
[error] |java.lang.AssertionError: assertion failed
[error] | at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:11)
[error] | at dotty.tools.dotc.ast.tpd$.Apply(tpd.scala:51)
[error] | at scala.quoted.runtime.impl.QuotesImpl.scala$quoted$runtime$impl$QuotesImpl$reflect$Apply$$$_$apply$$anonfun$14(QuotesImpl.scala:628)
[error] | at scala.quoted.runtime.impl.QuotesImpl$reflect$.scala$quoted$runtime$impl$QuotesImpl$reflect$$$withDefaultPos(QuotesImpl.scala:3010)
[error] | at scala.quoted.runtime.impl.QuotesImpl$reflect$Apply$.apply(QuotesImpl.scala:628)
[error] | at scala.quoted.runtime.impl.QuotesImpl$reflect$Apply$.apply(QuotesImpl.scala:626)
[error] | at x.X$.testImpl(X.scala:20)
[error] |
[error] |----------------------------------------------------------------------------
[error] |Inline stack trace
[error] |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error] |This location contains code that was inlined from X.scala:14
[error] 14 | inline def test(ref:IntRef):Int = ${ testImpl('ref) }
[error] | ^^^^^^^^^^^^^^^^^^^
[error] ----------------------------------------------------------------------------
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 3 s, completed 1 Jul 2023, 12:46:27
Expectation
It should be compiled.