@@ -20,19 +20,23 @@ import rewrites.Rewrites.patch
20
20
import util .Spans .Span
21
21
22
22
import util .SourcePosition
23
+ import util .Spans .Span
24
+ import rewrites .Rewrites .patch
23
25
import transform .SymUtils ._
26
+ import transform .ValueClasses ._
24
27
import Decorators ._
25
28
import ErrorReporting .{err , errorType }
26
29
import config .Printers .{typr , patmatch }
27
30
import NameKinds .DefaultGetterName
31
+ import SymDenotations .{NoCompleter , NoDenotation }
28
32
import Applications .unapplyArgs
29
33
import transform .patmat .SpaceEngine .isIrrefutableUnapply
30
34
35
+
31
36
import collection .mutable
32
- import SymDenotations .{NoCompleter , NoDenotation }
33
- import dotty .tools .dotc .reporting .diagnostic .Message
34
- import dotty .tools .dotc .reporting .diagnostic .messages ._
35
- import dotty .tools .dotc .transform .ValueClasses ._
37
+ import reporting .diagnostic .Message
38
+ import reporting .diagnostic .messages ._
39
+ import scala .tasty .util .Chars .isOperatorPart
36
40
37
41
object Checking {
38
42
import tpd ._
@@ -716,6 +720,24 @@ trait Checking {
716
720
i " Use of implicit conversion ${conv.showLocated}" , NoSymbol , posd.sourcePos)
717
721
}
718
722
723
+ /** Check that `tree` is a valid infix operation. That is, if the
724
+ * operator is alphanumeric, it must be declared `@infix`.
725
+ */
726
+ def checkValidInfix (tree : untpd.InfixOp , app : Tree )(implicit ctx : Context ): Unit =
727
+ tree.op match {
728
+ case Ident (name : SimpleName )
729
+ if ! name.exists(isOperatorPart) && ! app.symbol.hasAnnotation(defn.InfixAnnot ) && false =>
730
+ ctx.deprecationWarning(
731
+ i """ alphanumeric method $name is not declared @infix; should not be used as infix operator.
732
+ |The operation can be rewritten automatically under -migration -rewrite """ ,
733
+ tree.op.sourcePos)
734
+ if (ctx.scala2Mode) {
735
+ patch(Span (tree.op.span.start, tree.op.span.start), " `" )
736
+ patch(Span (tree.op.span.end, tree.op.span.end), " `" )
737
+ }
738
+ case _ =>
739
+ }
740
+
719
741
/** Issue a feature warning if feature is not enabled */
720
742
def checkFeature (name : TermName ,
721
743
description : => String ,
@@ -1099,5 +1121,6 @@ trait NoChecking extends ReChecking {
1099
1121
override def checkNoForwardDependencies (vparams : List [ValDef ])(implicit ctx : Context ): Unit = ()
1100
1122
override def checkMembersOK (tp : Type , pos : SourcePosition )(implicit ctx : Context ): Type = tp
1101
1123
override def checkInInlineContext (what : String , posd : Positioned )(implicit ctx : Context ): Unit = ()
1124
+ override def checkValidInfix (tree : untpd.InfixOp , app : Tree )(implicit ctx : Context ): Unit = ()
1102
1125
override def checkFeature (name : TermName , description : => String , featureUseSite : Symbol , pos : SourcePosition )(implicit ctx : Context ): Unit = ()
1103
1126
}
0 commit comments