Skip to content

Commit c9e67cb

Browse files
committed
More test cases
They should be sufficient to pin down the behavior.
1 parent aced916 commit c9e67cb

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

tests/run/contrarivant.scala

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
object Test extends App {
22

3+
// toplevel contra
34
implicit def f: String => String = x => "f"
4-
55
implicit def g: Object => String = x => "g"
6-
76
def h(implicit x: String => String) = x("")
7+
assert(h == "f", h)
88

9+
// nested contra
910
implicit def fs: List[String => String] = List(f)
10-
1111
implicit def gs: List[Object => String] = List(g)
12-
1312
def hs(implicit xs: List[String => String]) = xs.head("")
13+
assert(hs == "f", hs)
14+
15+
// covariant subapplication nested in toplevel contra
16+
implicit def f2: (Unit => String) => String = x => "f2"
17+
implicit def g2: (Unit => Object) => String = x => "g2"
18+
def h2(implicit x: (Unit => String) => String) = x(_ => "")
19+
assert(h2 == "f2", h2)
1420

15-
assert(h == "f")
16-
assert(hs == "f")
21+
// covariant subapplication nested in nested contra
22+
implicit def fs2: List[(Unit => String) => String] = List(f2)
23+
implicit def gs2: List[(Unit => Object) => String] = List(g2)
24+
def hs2(implicit xs: List[(Unit => String) => String]) = xs.head(_ => "")
25+
assert(hs2 == "f2", hs2)
1726
}

0 commit comments

Comments
 (0)