@@ -18,17 +18,20 @@ import CheckRealizable._
18
18
import ErrorReporting .errorTree
19
19
20
20
import util .SourcePosition
21
+ import util .Spans .Span
22
+ import rewrites .Rewrites .patch
21
23
import transform .SymUtils ._
24
+ import transform .ValueClasses ._
22
25
import Decorators ._
23
26
import ErrorReporting .{err , errorType }
24
27
import config .Printers .typr
25
28
import NameKinds .DefaultGetterName
29
+ import SymDenotations .{NoCompleter , NoDenotation }
26
30
27
31
import collection .mutable
28
- import SymDenotations .{NoCompleter , NoDenotation }
29
- import dotty .tools .dotc .reporting .diagnostic .Message
30
- import dotty .tools .dotc .reporting .diagnostic .messages ._
31
- import dotty .tools .dotc .transform .ValueClasses ._
32
+ import reporting .diagnostic .Message
33
+ import reporting .diagnostic .messages ._
34
+ import scala .tasty .util .Chars .isOperatorPart
32
35
33
36
object Checking {
34
37
import tpd ._
@@ -664,6 +667,24 @@ trait Checking {
664
667
i " Use of implicit conversion ${conv.showLocated}" , NoSymbol , posd.sourcePos)
665
668
}
666
669
670
+ /** Check that `tree` is a valid infix operation. That is, if the
671
+ * operator is alphanumeric, it must be declared `@infix`.
672
+ */
673
+ def checkValidInfix (tree : untpd.InfixOp , app : Tree )(implicit ctx : Context ): Unit =
674
+ tree.op match {
675
+ case Ident (name : SimpleName )
676
+ if ! name.exists(isOperatorPart) && ! app.symbol.hasAnnotation(defn.InfixAnnot ) && false =>
677
+ ctx.deprecationWarning(
678
+ i """ alphanumeric method $name is not declared @infix; should not be used as infix operator.
679
+ |The operation can be rewritten automatically under -migration -rewrite """ ,
680
+ tree.op.sourcePos)
681
+ if (ctx.scala2Mode) {
682
+ patch(Span (tree.op.span.start, tree.op.span.start), " `" )
683
+ patch(Span (tree.op.span.end, tree.op.span.end), " `" )
684
+ }
685
+ case _ =>
686
+ }
687
+
667
688
/** Issue a feature warning if feature is not enabled */
668
689
def checkFeature (name : TermName ,
669
690
description : => String ,
@@ -1053,5 +1074,6 @@ trait NoChecking extends ReChecking {
1053
1074
override def checkNoForwardDependencies (vparams : List [ValDef ])(implicit ctx : Context ): Unit = ()
1054
1075
override def checkMembersOK (tp : Type , pos : SourcePosition )(implicit ctx : Context ): Type = tp
1055
1076
override def checkInInlineContext (what : String , posd : Positioned )(implicit ctx : Context ): Unit = ()
1077
+ override def checkValidInfix (tree : untpd.InfixOp , app : Tree )(implicit ctx : Context ): Unit = ()
1056
1078
override def checkFeature (name : TermName , description : => String , featureUseSite : Symbol , pos : SourcePosition )(implicit ctx : Context ): Unit = ()
1057
1079
}
0 commit comments