Skip to content

Commit c192315

Browse files
Backport "Fix #20458: do not expose ClassInfo in quotes reflect widenTermRefByName" to LTS (#21152)
Backports #20468 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 5310094 + 680b045 commit c192315

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

+4-1
Original file line numberDiff line numberDiff line change
@@ -1781,7 +1781,10 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
17811781
def =:=(that: TypeRepr): Boolean = self =:= that
17821782
def <:<(that: TypeRepr): Boolean = self <:< that
17831783
def widen: TypeRepr = self.widen
1784-
def widenTermRefByName: TypeRepr = self.widenTermRefExpr
1784+
def widenTermRefByName: TypeRepr =
1785+
self.widenTermRefExpr match
1786+
case dotc.core.Types.ClassInfo(prefix, sym, _, _, _) => prefix.select(sym)
1787+
case other => other
17851788
def widenByName: TypeRepr = self.widenExpr
17861789
def dealias: TypeRepr = self.dealias
17871790
def simplified: TypeRepr = self.simplified

tests/pos-macros/i20458/Macro_1.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import scala.quoted._
2+
3+
inline def matchCustom[F](): Unit = ${ matchCustomImpl[F] }
4+
5+
private def matchCustomImpl[F: Type](using q: Quotes): Expr[Unit] = {
6+
import q.reflect.*
7+
val any = TypeRepr.of[Any].typeSymbol
8+
assert(!any.termRef.widenTermRefByName.toString.contains("ClassInfo"))
9+
any.termRef.widenTermRefByName.asType match
10+
case '[t] => ()
11+
'{ () }
12+
}

tests/pos-macros/i20458/Test_2.scala

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def main() = matchCustom()

0 commit comments

Comments
 (0)