Skip to content

Create TypeRepr of a type with projection #16305

Discussion options

You must be logged in to vote

A way to build it manually would be to do something like this:

import scala.quoted.*

trait ServiceK[U[_[_]]]
type IdK[A] = {
  type λ[F[_]] = F[A]
}

inline def idK: Boolean = ${ idKImpl }

def idKImpl(using Quotes): Expr[Boolean] = {
  import quotes.reflect.*

  val expected = TypeRepr.of[ServiceK[IdK[Int]#λ]]

  // IdK[Int] is encoded as
  // java.lang.Object {
  //   type λ >: [F >: scala.Nothing <: [_$3 >: scala.Nothing <: scala.Any] => scala.Any] => F[scala.Int] <: [F >: scala.Nothing <: [_$3 >: scala.Nothing <: scala.Any] => scala.Any] => F[scala.Int]
  // }
  // i.e. a Refinement type (Object + the type declaration)
  TypeRepr.of[IdK].appliedTo(TypeRepr.of[Int]) match {
    case repr

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@pomadchin
Comment options

@KacperFKorban
Comment options

@pomadchin
Comment options

Answer selected by KacperFKorban
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants