Skip to content

Commit

Permalink
Infix warn on migration
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed May 11, 2021
1 parent 2efc7ed commit d5cb78c
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 30 deletions.
6 changes: 5 additions & 1 deletion src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
Expand Up @@ -13,6 +13,7 @@
package scala.tools.nsc
package ast.parser

import scala.tools.nsc.settings.ScalaVersion
import scala.tools.nsc.util.{CharArrayReader, CharArrayReaderData}
import scala.reflect.internal.util._
import scala.reflect.internal.Chars._
Expand Down Expand Up @@ -403,6 +404,9 @@ trait Scanners extends ScannersCommon {
sepRegions = sepRegions.tail
}

/** True to warn about migration change in infix syntax. */
private val infixMigration = settings.Xmigration.value <= ScalaVersion("2.13.2")

/** Produce next token, filling TokenData fields of Scanner.
*/
def nextToken(): Unit = {
Expand Down Expand Up @@ -487,7 +491,7 @@ trait Scanners extends ScannersCommon {
|will be taken as an infix expression continued from the previous line.
|To force the previous interpretation as a separate statement,
|add an explicit `;`, add an empty line, or remove spaces after the operator."""
deprecationWarning(msg.stripMargin, "2.13.2")
if (infixMigration) deprecationWarning(msg.stripMargin, "2.13.2")
insertNL(NEWLINE)
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/multiLineOps.check
@@ -1,5 +1,5 @@
multiLineOps.scala:6: warning: a pure expression does nothing in statement position; multiline expressions may require enclosing parentheses
+3 // error: Expected a toplevel definition (or pure expr warning, here)
+3 // warning: a pure expression does nothing in statement position
^
error: No warnings can be incurred under -Werror.
1 warning
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/multiLineOps.scala
Expand Up @@ -3,5 +3,5 @@
class Test {
val x = 1
+ 2
+3 // error: Expected a toplevel definition (or pure expr warning, here)
+3 // warning: a pure expression does nothing in statement position
}
14 changes: 1 addition & 13 deletions test/files/neg/stmt-expr-discard.check
@@ -1,21 +1,9 @@
stmt-expr-discard.scala:5: warning: Line starts with an operator that in future
will be taken as an infix expression continued from the previous line.
To force the previous interpretation as a separate statement,
add an explicit `;`, add an empty line, or remove spaces after the operator.
+ 2
^
stmt-expr-discard.scala:6: warning: Line starts with an operator that in future
will be taken as an infix expression continued from the previous line.
To force the previous interpretation as a separate statement,
add an explicit `;`, add an empty line, or remove spaces after the operator.
- 4
^
stmt-expr-discard.scala:5: warning: a pure expression does nothing in statement position; multiline expressions may require enclosing parentheses
+ 2
^
stmt-expr-discard.scala:6: warning: a pure expression does nothing in statement position; multiline expressions may require enclosing parentheses
- 4
^
error: No warnings can be incurred under -Werror.
4 warnings
2 warnings
1 error
2 changes: 1 addition & 1 deletion test/files/neg/t12071.scala
@@ -1,4 +1,4 @@
// scalac: -Werror -Xlint
// scalac: -Werror -Xlint -Xmigration:2.13

class C {
def `c c`(n: Int): Int = n + 1
Expand Down
14 changes: 1 addition & 13 deletions test/files/neg/t9847.check
@@ -1,15 +1,3 @@
t9847.scala:10: warning: Line starts with an operator that in future
will be taken as an infix expression continued from the previous line.
To force the previous interpretation as a separate statement,
add an explicit `;`, add an empty line, or remove spaces after the operator.
+ 1
^
t9847.scala:14: warning: Line starts with an operator that in future
will be taken as an infix expression continued from the previous line.
To force the previous interpretation as a separate statement,
add an explicit `;`, add an empty line, or remove spaces after the operator.
+ 1
^
t9847.scala:6: warning: discarded non-Unit value
def f(): Unit = 42
^
Expand Down Expand Up @@ -47,5 +35,5 @@ t9847.scala:24: warning: a pure expression does nothing in statement position; m
class D { 42 ; 17 }
^
error: No warnings can be incurred under -Werror.
14 warnings
12 warnings
1 error

0 comments on commit d5cb78c

Please sign in to comment.