Skip to content

Commit

Permalink
Do not expose ClassInfo in widenTermRefByName
Browse files Browse the repository at this point in the history
Previously ClassInfo could be easily be exposed with calls like
`TypeRepr.of[T].termRef.widenTermRefByName`.

[Cherry-picked 5009065]
  • Loading branch information
jchyb authored and WojciechMazur committed Jul 10, 2024
1 parent fe9d465 commit 5f1c3c2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,10 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
def =:=(that: TypeRepr): Boolean = self =:= that
def <:<(that: TypeRepr): Boolean = self <:< that
def widen: TypeRepr = self.widen
def widenTermRefByName: TypeRepr = self.widenTermRefExpr
def widenTermRefByName: TypeRepr =
self.widenTermRefExpr match
case dotc.core.Types.ClassInfo(prefix, sym, _, _, _) => prefix.select(sym)
case other => other
def widenByName: TypeRepr = self.widenExpr
def dealias: TypeRepr = self.dealias
def simplified: TypeRepr = self.simplified
Expand Down
12 changes: 12 additions & 0 deletions tests/pos-macros/i20458/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import scala.quoted._

inline def matchCustom[F](): Unit = ${ matchCustomImpl[F] }

private def matchCustomImpl[F: Type](using q: Quotes): Expr[Unit] = {
import q.reflect.*
val any = TypeRepr.of[Any].typeSymbol
assert(!any.termRef.widenTermRefByName.toString.contains("ClassInfo"))
any.termRef.widenTermRefByName.asType match
case '[t] => ()
'{ () }
}
1 change: 1 addition & 0 deletions tests/pos-macros/i20458/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def main() = matchCustom()

0 comments on commit 5f1c3c2

Please sign in to comment.