Skip to content

Commit c082148

Browse files
natsukagamibracevac
authored andcommitted
isPureClass for checking whether a TypeRepr is pure from a given context
1 parent 08d5bdc commit c082148

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

scaladoc/src/dotty/tools/scaladoc/cc/CaptureOps.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,23 @@ extension (using qctx: Quotes)(tpe: qctx.reflect.TypeRepr) // FIXME clean up and
111111
tpe.isCapSet && tpe.match
112112
case CapturingType(_, List(ref)) => ref.isCaptureRoot
113113
case _ => false
114+
115+
def isPureClass(from: qctx.reflect.ClassDef): Boolean =
116+
import qctx.reflect._
117+
def check(sym: Tree): Boolean = sym match
118+
case ClassDef(name, _, _, Some(ValDef(_, tt, _)), _) => tt.tpe match
119+
case CapturingType(_, refs) => refs.isEmpty
120+
case _ => true
121+
case _ => false
122+
123+
// Horrible hack to basically grab tpe1.asSeenFrom(from)
124+
val tpe1 = from.symbol.typeRef.select(tpe.typeSymbol).simplified
125+
val tpe2 = tpe1.classSymbol.map(_.typeRef).getOrElse(tpe1)
126+
127+
// println(s"${tpe.show} -> (${tpe.typeSymbol} from ${from.symbol}) ${tpe1.show} -> ${tpe2} -> ${tpe2.baseClasses.filter(_.isClassDef)}")
128+
val res = tpe2.baseClasses.exists(c => c.isClassDef && check(c.tree))
129+
// println(s"${tpe.show} is pure class = $res")
130+
res
114131
end extension
115132

116133
extension (using qctx: Quotes)(typedef: qctx.reflect.TypeDef)

0 commit comments

Comments
 (0)