Skip to content

Commit 8b44ffa

Browse files
committed
Deprecation warnings for old syntax: alphanumeric infix operators
This is the first part of #18870
1 parent ff0b153 commit 8b44ffa

File tree

28 files changed

+128
-31
lines changed

28 files changed

+128
-31
lines changed

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import config.Printers.typr
3434
import dotty.tools.dotc.classpath.FileUtils.isScalaBinary
3535

3636
import scala.compiletime.uninitialized
37+
import dotty.tools.tasty.TastyVersion
3738

3839
object Symbols {
3940

@@ -281,6 +282,12 @@ object Symbols {
281282
def compilationUnitInfo(using Context): CompilationUnitInfo | Null =
282283
lastDenot.topLevelClass.compilationUnitInfo
283284

285+
/** The version of TASTy from which the symbol was loaded, None if not applicable. */
286+
def tastyVersion(using Context): Option[TastyVersion] =
287+
val compUnitInfo = compilationUnitInfo
288+
if compUnitInfo == null then None
289+
else compUnitInfo.tastyVersion
290+
284291
/** The class file from which this class was generated, null if not applicable. */
285292
final def binaryFile(using Context): AbstractFile | Null = {
286293
val file = associatedFile

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,12 +1071,17 @@ trait Checking {
10711071
def checkValidInfix(tree: untpd.InfixOp, meth: Symbol)(using Context): Unit = {
10721072
tree.op match {
10731073
case id @ Ident(name: Name) =>
1074+
def methCompiledBeforeDeprecation =
1075+
meth.tastyVersion match
1076+
case Some(version) => version.minor < 4 // compiled before 3.4
1077+
case _ => false // compiled with the current compiler
10741078
name.toTermName match {
10751079
case name: SimpleName
10761080
if !untpd.isBackquoted(id) &&
10771081
!name.isOperatorName &&
10781082
!meth.isDeclaredInfix &&
10791083
!meth.maybeOwner.is(Scala2x) &&
1084+
!methCompiledBeforeDeprecation &&
10801085
!infixOKSinceFollowedBy(tree.right) =>
10811086
val (kind, alternative) =
10821087
if (ctx.mode.is(Mode.Type))
@@ -1085,13 +1090,14 @@ trait Checking {
10851090
("extractor", (n: Name) => s"prefix syntax $n(...)")
10861091
else
10871092
("method", (n: Name) => s"method syntax .$n(...)")
1088-
def rewriteMsg = Message.rewriteNotice("The latter", version = `future-migration`)
1089-
report.errorOrMigrationWarning(
1093+
def rewriteMsg = Message.rewriteNotice("The latter", version = `3.4-migration`)
1094+
report.gradualErrorOrMigrationWarning(
10901095
em"""Alphanumeric $kind $name is not declared ${hlAsKeyword("infix")}; it should not be used as infix operator.
10911096
|Instead, use ${alternative(name)} or backticked identifier `$name`.$rewriteMsg""",
10921097
tree.op.srcPos,
1093-
from = future)
1094-
if sourceVersion == `future-migration` then {
1098+
warnFrom = `3.4`,
1099+
errorFrom = future)
1100+
if sourceVersion.isMigrating && sourceVersion.isAtLeast(`3.4-migration`) then {
10951101
patch(Span(tree.op.span.start, tree.op.span.start), "`")
10961102
patch(Span(tree.op.span.end, tree.op.span.end), "`")
10971103
}

compiler/test-resources/repl/i1374

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
scala> implicit class Padder(val sb: StringBuilder) extends AnyVal { def pad2(width: Int) = { 1 to width - sb.length foreach { sb append '*' }; sb } }
1+
scala> implicit class Padder(val sb: StringBuilder) extends AnyVal { infix def pad2(width: Int) = { 1 to width - sb.length foreach { sb append '*' }; sb } }
22
// defined class Padder
33
def Padder(sb: StringBuilder): Padder
44
scala> val greeting = new StringBuilder("Hello, kitteh!")

compiler/test-resources/type-printer/infix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def foo: (Int &: String) & Boolean
2929
scala> def foo: Int &: (Boolean & String) = ???
3030
def foo: Int &: (Boolean & String)
3131
scala> import scala.annotation.showAsInfix
32-
scala> @scala.annotation.showAsInfix class Mappy[T,U]
32+
scala> @scala.annotation.showAsInfix infix class Mappy[T,U]
3333
// defined class Mappy
3434
scala> def foo: (Int Mappy Boolean) && String = ???
3535
def foo: (Int Mappy Boolean) && String

language-server/test/dotty/tools/languageserver/util/embedded/CodeMarker.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import PositionContext.PosCtx
1313
class CodeMarker(val name: String) extends Embedded {
1414

1515
/** A range of positions between this marker and `other`. */
16-
def to(other: CodeMarker): CodeRange = CodeRange(this, other)
16+
infix def to(other: CodeMarker): CodeRange = CodeRange(this, other)
1717

1818
/** The file containing this marker. */
1919
def file: PosCtx[TestFile] = posCtx.positionOf(this)._1

scaladoc-testcases/src/tests/infixTypes.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ package infixTypes
44
import annotation.showAsInfix
55

66
@showAsInfix
7-
trait SomeTrait[A, B]
7+
infix trait SomeTrait[A, B]
88

9-
trait SomeTrait2[A, B]
9+
infix trait SomeTrait2[A, B]
1010

1111
def someTrait1[C, D]: C SomeTrait D
1212
= ???

scaladoc/src/dotty/tools/scaladoc/tasty/comments/MemberLookup.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ object MemberLookup extends MemberLookup {
236236
// Scaladoc overloading support allows terminal * (and they're meaningless)
237237
val cleanStr = str.stripSuffix("*")
238238

239-
if cleanStr endsWith "$" then
239+
if cleanStr.endsWith("$") then
240240
Selector(cleanStr.init, SelectorKind.ForceTerm)
241-
else if cleanStr endsWith "!" then
241+
else if cleanStr.endsWith("!") then
242242
Selector(cleanStr.init, SelectorKind.ForceType)
243243
else
244244
Selector(cleanStr, SelectorKind.NoForce)

scaladoc/src/dotty/tools/scaladoc/tasty/comments/wiki/Parser.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ sealed class CharReader(buffer: String) { reader =>
675675

676676
var offset: Int = 0
677677
def char: Char =
678-
if (offset >= buffer.length) endOfText else buffer charAt offset
678+
if (offset >= buffer.length) endOfText else buffer.charAt(offset)
679679

680680
final def nextChar() =
681681
offset += 1
@@ -712,7 +712,7 @@ sealed class CharReader(buffer: String) { reader =>
712712
jumpWhitespace()
713713
val (ok0, chars0) =
714714
if (chars.charAt(0) == ' ')
715-
(offset > poff, chars substring 1)
715+
(offset > poff, chars.substring(1))
716716
else
717717
(true, chars)
718718
val ok = ok0 && jump(chars0)

scaladoc/test/dotty/tools/scaladoc/testUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def tastyFiles(name: String, allowEmpty: Boolean = false, rootPck: String = "tes
7171
}
7272
def collectFiles(dir: File): List[File] = listFilesSafe(dir).toList.flatMap {
7373
case f if f.isDirectory => collectFiles(f)
74-
case f if f.getName endsWith ".tasty" => f :: Nil
74+
case f if f.getName.endsWith(".tasty") => f :: Nil
7575
case _ => Nil
7676
}
7777
val outputDir = BuildInfo.test_testcasesOutputDir

tests/init-global/pos/i18628-lazy.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ trait Parsers {
5555
}
5656

5757
def flatMap[U](f: T => Parser[U]): Parser[U]
58-
= Parser{ in => this(in) flatMapWithNext(f)}
58+
= Parser{ in => this(in).flatMapWithNext(f)}
5959

6060
def map[U](f: T => U): Parser[U] //= flatMap{x => success(f(x))}
61-
= Parser{ in => this(in) map(f)}
61+
= Parser{ in => this(in).map(f)}
6262

6363
def ^^ [U](f: T => U): Parser[U] = map(f)
6464
}

0 commit comments

Comments
 (0)