Skip to content

Commit 8567b73

Browse files
Close test: GADT constraint drives picking the right implicit (#16807)
Fixes #5469
2 parents 21729d2 + 26567e7 commit 8567b73

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

tests/run/i16785.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
specific: 1

tests/run/i16785.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
object Test {
2+
sealed trait Box[T] { def value: T }
3+
final case class IntBox(value: Int) extends Box[Int]
4+
5+
implicit def s1[T](implicit box: Box[T]): String = "generic: " + box.value
6+
implicit def s2(implicit box: Box[Int]): String = "specific: " + box.value
7+
8+
def test[T](implicit box: Box[T]): String = box match {
9+
case IntBox(_) => implicitly[String]
10+
}
11+
12+
def main(args: Array[String]): Unit =
13+
println(test(IntBox(1)))
14+
}

0 commit comments

Comments
 (0)