Skip to content

Commit afb4164

Browse files
committed
Deprecate view bounds without -Xfuture
Fixes scala/bug#10719 scala#2909 deprecated view bounds under -Xfuture. This deprecates it without it, and drops it under -Xsource:2.14.
1 parent ced7076 commit afb4164

9 files changed

+31
-16
lines changed

src/compiler/scala/tools/nsc/ast/parser/Parsers.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,10 +2425,11 @@ self =>
24252425
TypeDef(mods, pname, tparams, typeBounds())
24262426
}
24272427
if (contextBoundBuf ne null) {
2428+
def msg(what: String) = s"""view bounds are $what; use an implicit parameter instead.
2429+
| example: instead of `def f[A <% Int](a: A)` use `def f[A](a: A)(implicit ev: A => Int)`""".stripMargin
24282430
while (in.token == VIEWBOUND) {
2429-
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)`."
2430-
if (settings.future)
2431-
deprecationWarning(in.offset, s"View bounds are deprecated. $msg", "2.12.0")
2431+
if (settings.isScala214) syntaxError(in.offset, msg("unsupported"))
2432+
else deprecationWarning(in.offset, msg("deprecated"), "2.12.0")
24322433
contextBoundBuf += atPos(in.skipToken())(makeFunctionTypeTree(List(Ident(pname)), typ()))
24332434
}
24342435
while (in.token == COLON) {
@@ -2878,7 +2879,7 @@ self =>
28782879
classContextBounds = contextBoundBuf.toList
28792880
val tstart = (in.offset :: classContextBounds.map(_.pos.start)).min
28802881
if (!classContextBounds.isEmpty && mods.isTrait) {
2881-
val viewBoundsExist = if (settings.future) "" else " nor view bounds `<% ...'"
2882+
val viewBoundsExist = if (settings.isScala214) "" else " nor view bounds `<% ...'"
28822883
syntaxError(s"traits cannot have type parameters with context bounds `: ...'$viewBoundsExist", skipIt = false)
28832884
classContextBounds = List()
28842885
}

test/files/neg/t7629-view-bounds-deprecation.check

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/files/neg/t7629-view-bounds-deprecation.flags

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
view-bounds-deprecation.scala:2: warning: view bounds are deprecated; use an implicit parameter instead.
2+
example: instead of `def f[A <% Int](a: A)` use `def f[A](a: A)(implicit ev: A => Int)`
3+
def f[A <% Int](a: A) = null
4+
^
5+
view-bounds-deprecation.scala:3: warning: view bounds are deprecated; use an implicit parameter instead.
6+
example: instead of `def f[A <% Int](a: A)` use `def f[A](a: A)(implicit ev: A => Int)`
7+
def g[C, B <: C, A <% B : Numeric](a: A) = null
8+
^
9+
error: No warnings can be incurred under -Xfatal-warnings.
10+
two warnings found
11+
one error found
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-deprecation -Xfatal-warnings
File renamed without changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
view-bounds-removal.scala:2: error: view bounds are unsupported; use an implicit parameter instead.
2+
example: instead of `def f[A <% Int](a: A)` use `def f[A](a: A)(implicit ev: A => Int)`
3+
def f[A <% Int](a: A) = null
4+
^
5+
view-bounds-removal.scala:3: error: view bounds are unsupported; use an implicit parameter instead.
6+
example: instead of `def f[A <% Int](a: A)` use `def f[A](a: A)(implicit ev: A => Int)`
7+
def g[C, B <: C, A <% B : Numeric](a: A) = null
8+
^
9+
two errors found
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Xsource:2.14
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Test {
2+
def f[A <% Int](a: A) = null
3+
def g[C, B <: C, A <% B : Numeric](a: A) = null
4+
}

0 commit comments

Comments
 (0)