Skip to content

Fix for #17445 #21323

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,14 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler

def overloaded(qualifier: Term, name: String, targs: List[TypeRepr], args: List[Term], returnType: TypeRepr): Term =
withDefaultPos(tpd.applyOverloaded(qualifier, name.toTermName, args, targs, returnType))

def copy(original: Tree)(qualifier: Term, name: String): Select =
val sym = original.symbol
if sym.name.is(NameKinds.DefaultGetterName) && sym.name.toString == name then
tpd.cpy.Select(original)(qualifier, sym.name)
else
tpd.cpy.Select(original)(qualifier, name.toTermName)

def unapply(x: Select): (Term, String) =
(x.qualifier, x.name.toString)
end Select
Expand Down
21 changes: 21 additions & 0 deletions tests/pos-macros/i17445/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package i17445

import scala.quoted.*
import scala.collection.*


object Macro {

inline def changeIndexWhere[A](inline expr: A): A =
${ changeIndexWhereImpl('expr) }

def changeIndexWhereImpl[A: Type](expr: Expr[A])(using Quotes): Expr[A] = {
import quotes.reflect.*
val r0 = expr.asTerm
val checker = new TreeMap() {}
println(r0.getClass().getSimpleName())
val r = checker.transformTerm(r0)(Symbol.spliceOwner)
r.asExprOf[A]
}

}
9 changes: 9 additions & 0 deletions tests/pos-macros/i17445/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//> using options -Ydebug
package i17445

def complileMe:Int =
Macro.changeIndexWhere {
val arr = Array(1, 2, 3)
val result = arr.indexWhere(_ == 2)
result
}
Loading