-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15655 from dotty-staging/fix-implicit-loop-check
Fix looping implicits check
- Loading branch information
Showing
4 changed files
with
45 additions
and
134 deletions.
There are no files selected for viewing
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
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
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
43 changes: 43 additions & 0 deletions
43
tests/pos-special/fatal-warnings/not-looping-implicit.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import scala.deriving.Mirror | ||
import scala.compiletime._ | ||
|
||
trait Schema[T] | ||
|
||
object Schema { | ||
implicit val stringSchema: Schema[String] = new Schema[String] {} | ||
implicit def listSchema[A](implicit ev: Schema[A]): Schema[List[A]] = new Schema[List[A]] {} | ||
implicit def mapSchema[A, B](implicit evA: Schema[A], evB: Schema[B]): Schema[Map[A, B]] = | ||
new Schema[Map[A, B]] {} | ||
|
||
inline def recurse[Label, A <: Tuple](index: Int = 0): List[(String, Schema[Any], Int)] = | ||
inline erasedValue[(Label, A)] match { | ||
case (_: (name *: names), _: (t *: ts)) => | ||
val label = constValue[name].toString | ||
val builder = summonInline[Schema[t]].asInstanceOf[Schema[Any]] | ||
(label, builder, index) :: recurse[names, ts](index + 1) | ||
case (_: EmptyTuple, _) => Nil | ||
} | ||
|
||
inline def derived[A]: Schema[A] = | ||
inline summonInline[Mirror.Of[A]] match { | ||
case m: Mirror.SumOf[A] => | ||
lazy val members = recurse[m.MirroredElemLabels, m.MirroredElemTypes]() | ||
new Schema[A] {} | ||
case m: Mirror.ProductOf[A] => | ||
lazy val fields = recurse[m.MirroredElemLabels, m.MirroredElemTypes]() | ||
new Schema[A] {} | ||
} | ||
|
||
inline given gen[A]: Schema[A] = derived[A] | ||
} | ||
|
||
sealed trait InputValue | ||
object InputValue { | ||
case class ListValue(values: List[InputValue]) extends InputValue | ||
case class ObjectValue(fields: Map[String, InputValue]) extends InputValue | ||
case class VariableValue(name: String) extends InputValue | ||
} | ||
|
||
@main def Test = | ||
implicit lazy val inputValueSchema: Schema[InputValue] = Schema.gen | ||
println(summon[Schema[InputValue]]) |