diff options
author | Simon Ochsenreither <simon@ochsenreither.de> | 2013-08-20 18:19:33 +0200 |
---|---|---|
committer | Simon Ochsenreither <simon@ochsenreither.de> | 2013-09-25 15:16:12 +0200 |
commit | 96ff8c5d0b49a0c6c7353c57abe9bc10e6aed70f (patch) | |
tree | cd55b66d53c99df3af445366bd86faed7e6adfae | |
parent | bda48577d022811be58ce2b7f9e46890543ad45b (diff) | |
download | scala-96ff8c5d0b49a0c6c7353c57abe9bc10e6aed70f.tar.gz scala-96ff8c5d0b49a0c6c7353c57abe9bc10e6aed70f.tar.bz2 scala-96ff8c5d0b49a0c6c7353c57abe9bc10e6aed70f.zip |
SI-7629 Deprecate view bounds
This introduces a warning(/error with -Xfuture) with a general
migration advice. The IDE can use the warning to offer a quick fix
with the specific refactoring necessary.
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 10 | ||||
-rw-r--r-- | test/files/neg/t7629-view-bounds-deprecation.check | 11 | ||||
-rw-r--r-- | test/files/neg/t7629-view-bounds-deprecation.flags | 1 | ||||
-rw-r--r-- | test/files/neg/t7629-view-bounds-deprecation.scala | 4 | ||||
-rw-r--r-- | test/pending/t7629-view-bounds-removal.check | 9 | ||||
-rw-r--r-- | test/pending/t7629-view-bounds-removal.flags | 1 | ||||
-rw-r--r-- | test/pending/t7629-view-bounds-removal.scala | 4 |
7 files changed, 36 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index a894e38ab4..c9e209f53b 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -2257,9 +2257,10 @@ self => } if (contextBoundBuf ne null) { while (in.token == VIEWBOUND) { - contextBoundBuf += atPos(in.skipToken()) { - makeFunctionTypeTree(List(Ident(pname)), typ()) - } + 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") + contextBoundBuf += atPos(in.skipToken())(makeFunctionTypeTree(List(Ident(pname)), typ())) } while (in.token == COLON) { contextBoundBuf += atPos(in.skipToken()) { @@ -2690,7 +2691,8 @@ self => classContextBounds = contextBoundBuf.toList val tstart = (in.offset :: classContextBounds.map(_.pos.startOrPoint)).min if (!classContextBounds.isEmpty && mods.isTrait) { - syntaxError("traits cannot have type parameters with context bounds `: ...' nor view bounds `<% ...'", skipIt = false) + val viewBoundsExist = if (settings.future) "" else " nor view bounds `<% ...'" + syntaxError(s"traits cannot have type parameters with context bounds `: ...'$viewBoundsExist", skipIt = false) classContextBounds = List() } val constrAnnots = if (!mods.isTrait) constructorAnnotations() else Nil diff --git a/test/files/neg/t7629-view-bounds-deprecation.check b/test/files/neg/t7629-view-bounds-deprecation.check new file mode 100644 index 0000000000..ed77c15c54 --- /dev/null +++ b/test/files/neg/t7629-view-bounds-deprecation.check @@ -0,0 +1,11 @@ +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 new file mode 100644 index 0000000000..43a25d4ccc --- /dev/null +++ b/test/files/neg/t7629-view-bounds-deprecation.flags @@ -0,0 +1 @@ +-deprecation -Xfatal-warnings -Xfuture diff --git a/test/files/neg/t7629-view-bounds-deprecation.scala b/test/files/neg/t7629-view-bounds-deprecation.scala new file mode 100644 index 0000000000..a6ede1fcc3 --- /dev/null +++ b/test/files/neg/t7629-view-bounds-deprecation.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/pending/t7629-view-bounds-removal.check b/test/pending/t7629-view-bounds-removal.check new file mode 100644 index 0000000000..dc52105eaf --- /dev/null +++ b/test/pending/t7629-view-bounds-removal.check @@ -0,0 +1,9 @@ +t7629-view-bounds-removal.scala:2: error: View bounds have been removed. 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-removal.scala:3: error: View bounds have been removed. 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/pending/t7629-view-bounds-removal.flags b/test/pending/t7629-view-bounds-removal.flags new file mode 100644 index 0000000000..29f4ede37a --- /dev/null +++ b/test/pending/t7629-view-bounds-removal.flags @@ -0,0 +1 @@ +-Xfuture diff --git a/test/pending/t7629-view-bounds-removal.scala b/test/pending/t7629-view-bounds-removal.scala new file mode 100644 index 0000000000..a6ede1fcc3 --- /dev/null +++ b/test/pending/t7629-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 +} |