Skip to content

Commit 5f1c3c2

Browse files
jchybWojciechMazur
authored andcommitted
Do not expose ClassInfo in widenTermRefByName
Previously ClassInfo could be easily be exposed with calls like `TypeRepr.of[T].termRef.widenTermRefByName`. [Cherry-picked 5009065]
1 parent fe9d465 commit 5f1c3c2

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 12 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def main() = matchCustom()

0 commit comments

Comments
 (0)