Skip to content

Commit

Permalink
Merge pull request scala#6500 from eed3si9n/wip/deprecate-view-bounds
Browse files Browse the repository at this point in the history
scala/bug#10719. Deprecate view bounds without -Xfuture
  • Loading branch information
adriaanm authored Apr 10, 2018
2 parents 48c7ef4 + 14f1dd8 commit ab22def
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 22 deletions.
9 changes: 5 additions & 4 deletions src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2425,10 +2425,11 @@ self =>
TypeDef(mods, pname, tparams, typeBounds())
}
if (contextBoundBuf ne null) {
def msg(what: String) = s"""view bounds are $what; use an implicit parameter instead.
| example: instead of `def f[A <% Int](a: A)` use `def f[A](a: A)(implicit ev: A => Int)`""".stripMargin
while (in.token == VIEWBOUND) {
val msg = "Use an implicit parameter instead.\nExample: Instead of `def f[A <% Int](a: A)` use `def f[A](a: A)(implicit ev: A => Int)`."
if (settings.future)
deprecationWarning(in.offset, s"View bounds are deprecated. $msg", "2.12.0")
if (settings.isScala214) syntaxError(in.offset, msg("unsupported"))
else deprecationWarning(in.offset, msg("deprecated"), "2.12.0")
contextBoundBuf += atPos(in.skipToken())(makeFunctionTypeTree(List(Ident(pname)), typ()))
}
while (in.token == COLON) {
Expand Down Expand Up @@ -2878,7 +2879,7 @@ self =>
classContextBounds = contextBoundBuf.toList
val tstart = (in.offset :: classContextBounds.map(_.pos.start)).min
if (!classContextBounds.isEmpty && mods.isTrait) {
val viewBoundsExist = if (settings.future) "" else " nor view bounds `<% ...'"
val viewBoundsExist = if (settings.isScala214) "" else " nor view bounds `<% ...'"
syntaxError(s"traits cannot have type parameters with context bounds `: ...'$viewBoundsExist", skipIt = false)
classContextBounds = List()
}
Expand Down
4 changes: 2 additions & 2 deletions test/files/neg/overloaded-implicit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ object Test {
implicit def imp1[T](x: List[T]): Map[T, T] = Map()
implicit def imp1[T](x: Set[T]): Map[T, T] = Map()

def f[T <% Map[Int, Int]](x: T): Double = 1.0d
def f[T](x: T)(implicit ev: T => Map[Int, Int]): Double = 1.0d

// not parameterized, no warning
implicit def imp2(x: List[Int]): String = "a"
implicit def imp2(x: Set[Int]): String = "b"

def g[T <% String](x: T): Double = 2.0d
def g[T](x: T)(implicit ev: T => String): Double = 2.0d

def main(args: Array[String]): Unit = {
// println(f(List(1)))
Expand Down
11 changes: 0 additions & 11 deletions test/files/neg/t7629-view-bounds-deprecation.check

This file was deleted.

1 change: 0 additions & 1 deletion test/files/neg/t7629-view-bounds-deprecation.flags

This file was deleted.

11 changes: 11 additions & 0 deletions test/files/neg/view-bounds-deprecation.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
view-bounds-deprecation.scala:2: warning: view bounds are deprecated; use an implicit parameter instead.
example: instead of `def f[A <% Int](a: A)` use `def f[A](a: A)(implicit ev: A => Int)`
def f[A <% Int](a: A) = null
^
view-bounds-deprecation.scala:3: warning: view bounds are deprecated; use an implicit parameter instead.
example: instead of `def f[A <% Int](a: A)` use `def f[A](a: A)(implicit ev: A => Int)`
def g[C, B <: C, A <% B : Numeric](a: A) = null
^
error: No warnings can be incurred under -Xfatal-warnings.
two warnings found
one error found
1 change: 1 addition & 0 deletions test/files/neg/view-bounds-deprecation.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-deprecation -Xfatal-warnings
9 changes: 9 additions & 0 deletions test/files/neg/view-bounds-removal.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
view-bounds-removal.scala:2: error: view bounds are unsupported; use an implicit parameter instead.
example: instead of `def f[A <% Int](a: A)` use `def f[A](a: A)(implicit ev: A => Int)`
def f[A <% Int](a: A) = null
^
view-bounds-removal.scala:3: error: view bounds are unsupported; use an implicit parameter instead.
example: instead of `def f[A <% Int](a: A)` use `def f[A](a: A)(implicit ev: A => Int)`
def g[C, B <: C, A <% B : Numeric](a: A) = null
^
two errors found
1 change: 1 addition & 0 deletions test/files/neg/view-bounds-removal.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Xsource:2.14
4 changes: 4 additions & 0 deletions test/files/neg/view-bounds-removal.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Test {
def f[A <% Int](a: A) = null
def g[C, B <: C, A <% B : Numeric](a: A) = null
}
8 changes: 4 additions & 4 deletions test/files/run/iterator-from.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object Test extends App {
val maxKey = 50
val maxValue = 50

def testSet[A <% Ordered[A]](set: SortedSet[A], list: List[A]) {
def testSet[A](set: SortedSet[A], list: List[A])(implicit ev: A => Ordered[A]): Unit = {
val distinctSorted = list.distinct.sorted
assertEquals("Set size wasn't the same as list sze", set.size, distinctSorted.size)

Expand All @@ -24,7 +24,7 @@ object Test extends App {
}
}

def testMap[A <% Ordered[A], B](map: SortedMap[A, B], list: List[(A, B)]) {
def testMap[A, B](map: SortedMap[A, B], list: List[(A, B)])(implicit ev: A => Ordered[A]): Unit = {
val distinctSorted = distinctByKey(list).sortBy(_._1)
assertEquals("Map size wasn't the same as list sze", map.size, distinctSorted.size)

Expand All @@ -39,11 +39,11 @@ object Test extends App {
}
}

def check[A](clazz: Class[_], list: List[_], m1: String, m2: String, l1: List[A], l2: List[A]) {
def check[A](clazz: Class[_], list: List[_], m1: String, m2: String, l1: List[A], l2: List[A]): Unit = {
assertEquals(s"$clazz: `$m1` didn't match `$m2` on list $list", l1, l2)
}

def assertEquals[A](msg: String, x: A, y: A) {
def assertEquals[A](msg: String, x: A, y: A): Unit = {
assert(x == y, s"$msg\n1: $x\n2: $y")
}

Expand Down
4 changes: 4 additions & 0 deletions test/files/run/macro-expand-implicit-macro-is-view.check
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
Macros_Test_2.scala:10: warning: view bounds are deprecated; use an implicit parameter instead.
example: instead of `def f[A <% Int](a: A)` use `def f[A](a: A)(implicit ev: A => Int)`
def bar[T <% Option[Int]](x: T) = println(x)
^
2
1 change: 1 addition & 0 deletions test/files/run/macro-expand-implicit-macro-is-view.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-deprecation
1 change: 1 addition & 0 deletions test/files/run/t3346e.check
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
warning: there were two deprecation warnings (since 2.12.0); re-run with -deprecation for details
eqw
List(0, 2)
List(0, 2)
Expand Down

0 comments on commit ab22def

Please sign in to comment.