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 513a76c commit 24f394e
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,16 @@ 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)
val dealiased = t.dealias
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.dealias)
case _ =>
surfaceOf(t.simplified)

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

0 comments on commit 24f394e

Please sign in to comment.