Skip to content
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

Review/7629 deprecate view bounds #1

Closed
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
13 changes: 11 additions & 2 deletions src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2258,7 +2258,15 @@ self =>
if (contextBoundBuf ne null) {
while (in.token == VIEWBOUND) {
contextBoundBuf += atPos(in.skipToken()) {
makeFunctionTypeTree(List(Ident(pname)), typ())
val t = typ()
def discourage() = {
val msg = "Use an implicit parameter instead."
val eg = s"Instead of `def $owner[$pname <% $t](p: $pname)`, use `def $owner(p: $pname)(implicit ev: $pname => $t)`."
if (settings.future) syntaxError(in.offset, f"View bounds have been removed. $msg%n$eg")
else deprecationWarning(in.offset, f"View bounds are deprecated. $msg%n$eg")
}
discourage()
makeFunctionTypeTree(List(Ident(pname)), t)
}
}
while (in.token == COLON) {
Expand Down Expand Up @@ -2690,7 +2698,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
Expand Down
8 changes: 8 additions & 0 deletions test/files/run/iterator-from.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
iterator-from.scala:14: warning: View bounds are deprecated. Use an implicit parameter instead.
Instead of `def testSet[A <% Ordered[A]](p: A)`, use `def testSet(p: A)(implicit ev: A => Ordered[A])`.
def testSet[A <% Ordered[A]](set: SortedSet[A], list: List[A]) {
^
iterator-from.scala:27: warning: View bounds are deprecated. Use an implicit parameter instead.
Instead of `def testMap[A <% Ordered[A]](p: A)`, use `def testMap(p: A)(implicit ev: A => Ordered[A])`.
def testMap[A <% Ordered[A], B](map: SortedMap[A, B], list: List[(A, B)]) {
^
1 change: 1 addition & 0 deletions test/files/run/iterator-from.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-deprecation
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.
Instead of `def bar[T <% Option[Int]](p: T)`, use `def bar(p: T)(implicit ev: T => Option[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