Created
February 21, 2021 01:48
-
-
Save xuwei-k/7c3f662a78fdd39ce00db43900470848 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sbt.version=1.4.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scalaVersion := "3.0.0-RC1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.deriving.Mirror | |
import scala.compiletime.{erasedValue, summonInline} | |
object Macros { | |
inline def values[A](using inline A: Mirror.SumOf[A]): List[A] = | |
summonValues[A.MirroredElemTypes].asInstanceOf[List[A]] | |
inline def summonValues[T <: Tuple]: List[Any] = | |
inline erasedValue[T] match { | |
case _: EmptyTuple => | |
Nil | |
case _: (t *: ts) => | |
summonInline[ValueOf[t]].value :: summonValues[ts] | |
} | |
} | |
sealed trait A | |
case object B extends A | |
case object C extends A | |
case object D extends A | |
object Main { | |
def main(args: Array[String]): Unit = { | |
val x = Macros.values[A] | |
println(x) | |
assert(x.toSet == Set(B, C, D)) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.5.3") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment