diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 114935386161..3b0eb349b1a9 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -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) { @@ -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() } diff --git a/test/files/neg/overloaded-implicit.scala b/test/files/neg/overloaded-implicit.scala index 68b1ceaa30b7..263d8c0262c5 100644 --- a/test/files/neg/overloaded-implicit.scala +++ b/test/files/neg/overloaded-implicit.scala @@ -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))) diff --git a/test/files/neg/t7629-view-bounds-deprecation.check b/test/files/neg/t7629-view-bounds-deprecation.check deleted file mode 100644 index ed77c15c547b..000000000000 --- a/test/files/neg/t7629-view-bounds-deprecation.check +++ /dev/null @@ -1,11 +0,0 @@ -t7629-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 - ^ -t7629-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 diff --git a/test/files/neg/t7629-view-bounds-deprecation.flags b/test/files/neg/t7629-view-bounds-deprecation.flags deleted file mode 100644 index 43a25d4ccc01..000000000000 --- a/test/files/neg/t7629-view-bounds-deprecation.flags +++ /dev/null @@ -1 +0,0 @@ --deprecation -Xfatal-warnings -Xfuture diff --git a/test/files/neg/view-bounds-deprecation.check b/test/files/neg/view-bounds-deprecation.check new file mode 100644 index 000000000000..7550802d2e1d --- /dev/null +++ b/test/files/neg/view-bounds-deprecation.check @@ -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 diff --git a/test/files/neg/view-bounds-deprecation.flags b/test/files/neg/view-bounds-deprecation.flags new file mode 100644 index 000000000000..c6bfaf1f64a4 --- /dev/null +++ b/test/files/neg/view-bounds-deprecation.flags @@ -0,0 +1 @@ +-deprecation -Xfatal-warnings diff --git a/test/files/neg/t7629-view-bounds-deprecation.scala b/test/files/neg/view-bounds-deprecation.scala similarity index 100% rename from test/files/neg/t7629-view-bounds-deprecation.scala rename to test/files/neg/view-bounds-deprecation.scala diff --git a/test/files/neg/view-bounds-removal.check b/test/files/neg/view-bounds-removal.check new file mode 100644 index 000000000000..fbcffe46a0bd --- /dev/null +++ b/test/files/neg/view-bounds-removal.check @@ -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 diff --git a/test/files/neg/view-bounds-removal.flags b/test/files/neg/view-bounds-removal.flags new file mode 100644 index 000000000000..7a269652ae4b --- /dev/null +++ b/test/files/neg/view-bounds-removal.flags @@ -0,0 +1 @@ +-Xsource:2.14 diff --git a/test/files/neg/view-bounds-removal.scala b/test/files/neg/view-bounds-removal.scala new file mode 100644 index 000000000000..a6ede1fcc3dd --- /dev/null +++ b/test/files/neg/view-bounds-removal.scala @@ -0,0 +1,4 @@ +object Test { + def f[A <% Int](a: A) = null + def g[C, B <: C, A <% B : Numeric](a: A) = null +} diff --git a/test/files/run/iterator-from.scala b/test/files/run/iterator-from.scala index 01006ffc214b..4f5814cab94d 100644 --- a/test/files/run/iterator-from.scala +++ b/test/files/run/iterator-from.scala @@ -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) @@ -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) @@ -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") } diff --git a/test/files/run/macro-expand-implicit-macro-is-view.check b/test/files/run/macro-expand-implicit-macro-is-view.check index 0cfbf08886fc..f17fbc1db073 100644 --- a/test/files/run/macro-expand-implicit-macro-is-view.check +++ b/test/files/run/macro-expand-implicit-macro-is-view.check @@ -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 diff --git a/test/files/run/macro-expand-implicit-macro-is-view.flags b/test/files/run/macro-expand-implicit-macro-is-view.flags new file mode 100644 index 000000000000..dcc59ebe32ef --- /dev/null +++ b/test/files/run/macro-expand-implicit-macro-is-view.flags @@ -0,0 +1 @@ +-deprecation diff --git a/test/files/run/t3346e.check b/test/files/run/t3346e.check index 71a57ffa7062..dfec57765e0b 100644 --- a/test/files/run/t3346e.check +++ b/test/files/run/t3346e.check @@ -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)