Skip to content

Commit e1ced2e

Browse files
committed
Some more tests
1 parent b380fb0 commit e1ced2e

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

tests/neg/implicitSearch.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
object Test {
2+
3+
type T = String
4+
5+
class Ord[T]
6+
implicit def listOrd[T](implicit o: Ord[T]): Ord[List[T]] = ???
7+
implicit def intOrd: Ord[Int] = ???
8+
9+
def sort[T](xs: List[T])(implicit o: Ord[T]): List[T] = ???
10+
11+
def g(xs: List[Int]) =
12+
sort(xs)
13+
14+
def f[T](xs: List[List[List[T]]]) =
15+
sort(xs) // error TODO: improve the -explain-implicts diagnostic
16+
17+
listOrd(listOrd(implicitly[Ord[T]] /*not found*/)) // error
18+
}

tests/pos/cm/ConfManagement.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package cm
2+
3+
case class Person(name: String)
4+
case class Paper(title: String, authors: List[Person], body: String)
5+
6+
class Viewers(val persons: Set[Person])
7+
8+
class ConfManagement(papers: List[Paper], realScore: Map[Paper, Int]) {
9+
10+
private def hasConflict(ps1: Set[Person], ps2: Iterable[Person]) =
11+
ps2.exists(ps1 contains _)
12+
13+
def viewers(implicit vs: Viewers): Set[Person] =
14+
vs.persons
15+
16+
def score(paper: Paper)(implicit vs: Viewers): Int =
17+
if (hasConflict(viewers, paper.authors)) -100
18+
else realScore(paper)
19+
20+
def viewRankings(implicit vs: Viewers): List[Paper] =
21+
papers.sortBy(score(_))
22+
23+
def delegate[T](query: Viewers => T, p: Person)(implicit vs: Viewers): T =
24+
query(new Viewers(viewers + p))
25+
}

tests/run/i2508.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
trait Eq[T] {
2+
def eq(a: T, b: T): Boolean
3+
}
4+
5+
object Eq {
6+
implicit object int extends Eq[Int] {
7+
def eq(a: Int, b: Int) = a == b
8+
}
9+
}
10+
11+
object Test {
12+
def f[T](a: T, b: T)(implicit T: Eq[T]) = T.eq(a, b)
13+
14+
def main(args: Array[String]) =
15+
assert(!f(1, 2))
16+
}

0 commit comments

Comments
 (0)