Skip to content

Commit

Permalink
Merge pull request #1 from tpolecat/cleanup
Browse files Browse the repository at this point in the history
cleanup
  • Loading branch information
tpolecat authored Nov 20, 2020
2 parents 1385689 + 3a76164 commit 8f19cb0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/main/scala-2/TypeNamePlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ trait TypeNamePlatform {

object TypeNamePlatform {

// https://stackoverflow.com/questions/15649720
def typeName_impl[T](c: Context): c.Expr[TypeName[T]] = {
import c.universe._
val TypeApply(_, List(typeTree)) = c.macroApplication
Expand Down
7 changes: 4 additions & 3 deletions src/main/scala-3/TypeNamePlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import scala.quoted._

trait TypeNamePlatform {

transparent inline given instance[A] as TypeName[A] = ${TypeNamePlatform.impl[A]}
inline given [A] as TypeName[A] =
${TypeNamePlatform.impl[A]}

}

object TypeNamePlatform {

def impl[A](using t: Type[A], ctx: QuoteContext): Expr[TypeName[A]] = {
// https://users.scala-lang.org/t/obtaining-the-name-of-a-type-scala-3/6902/7
def impl[A](using t: Type[A], ctx: QuoteContext): Expr[TypeName[A]] =
'{TypeName[A](${Expr(t.show)})}
}

}

0 comments on commit 8f19cb0

Please sign in to comment.