Skip to content

Some more tests #2726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/neg/implicitSearch.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
object Test {

type T = String

class Ord[T]
implicit def listOrd[T](implicit o: Ord[T]): Ord[List[T]] = ???
implicit def intOrd: Ord[Int] = ???

def sort[T](xs: List[T])(implicit o: Ord[T]): List[T] = ???

def g(xs: List[Int]) =
sort(xs)

def f[T](xs: List[List[List[T]]]) =
sort(xs) // error TODO: improve the -explain-implicts diagnostic

listOrd(listOrd(implicitly[Ord[T]] /*not found*/)) // error
}
25 changes: 25 additions & 0 deletions tests/pos/cm/ConfManagement.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cm

case class Person(name: String)
case class Paper(title: String, authors: List[Person], body: String)

class Viewers(val persons: Set[Person])

class ConfManagement(papers: List[Paper], realScore: Map[Paper, Int]) {

private def hasConflict(ps1: Set[Person], ps2: Iterable[Person]) =
ps2.exists(ps1 contains _)

def viewers(implicit vs: Viewers): Set[Person] =
vs.persons

def score(paper: Paper)(implicit vs: Viewers): Int =
if (hasConflict(viewers, paper.authors)) -100
else realScore(paper)

def viewRankings(implicit vs: Viewers): List[Paper] =
papers.sortBy(score(_))

def delegate[T](query: Viewers => T, p: Person)(implicit vs: Viewers): T =
query(new Viewers(viewers + p))
}
16 changes: 16 additions & 0 deletions tests/run/i2508.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
trait Eq[T] {
def eq(a: T, b: T): Boolean
}

object Eq {
implicit object int extends Eq[Int] {
def eq(a: Int, b: Int) = a == b
}
}

object Test {
def f[T](a: T, b: T)(implicit T: Eq[T]) = T.eq(a, b)

def main(args: Array[String]) =
assert(!f(1, 2))
}