Skip to content

Commit

Permalink
Simplify extractSymbol - avoid .tree
Browse files Browse the repository at this point in the history
  • Loading branch information
OndrejSpanel committed May 14, 2024
1 parent a800caf commit fb755f9
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,15 @@ private[surface] class CompileTimeSurfaceFactory[Q <: Quotes](using quotes: Q):

private def extractSymbol(t: TypeRepr) =
val dealiased = t.dealias
val symbolInOwner = t.typeSymbol.maybeOwner.declarations.find(_.name.toString == t.typeSymbol.name.toString)
symbolInOwner.map(_.tree) match
case Some(TypeDef(_, b: TypeTree)) if t == dealiased =>
// t.dealias does not dealias for path dependent types, so extracting the dealiased type from AST.
surfaceOf(b.tpe)
case _ =>
if t != dealiased then surfaceOf(dealiased)
else surfaceOf(t.simplified)
if t != dealiased then surfaceOf(dealiased)
else
// t.dealias does not dealias for path dependent types, so try to find a matching inner type
val symbolInOwner = t.typeSymbol.maybeOwner.declarations.find(_.name.toString == t.typeSymbol.name.toString)
symbolInOwner match
case Some(sym) =>
surfaceOf(sym.typeRef)
case _ =>
surfaceOf(t.simplified)

private def aliasFactory: Factory = {
case t if t.typeSymbol.typeRef.isOpaqueAlias =>
Expand Down

0 comments on commit fb755f9

Please sign in to comment.