@@ -274,6 +274,20 @@ object Checking {
274274 }
275275 }
276276
277+ /** If `sym` has an operator name, check that it has an @alpha annotation under -strict */
278+ def checkValidOperator (sym : Symbol )(implicit ctx : Context ): Unit =
279+ sym.name.toTermName match {
280+ case name : SimpleName
281+ if name.exists(isOperatorPart) &&
282+ ! sym.getAnnotation(defn.AlphaAnnot ).isDefined &&
283+ ! sym.is(Synthetic ) &&
284+ ! name.isConstructorName &&
285+ ctx.settings.strict.value =>
286+ ctx.deprecationWarning(
287+ i " $sym has an operator name; it should come with an @alpha annotation " , sym.sourcePos)
288+ case _ =>
289+ }
290+
277291 /** Check that `info` of symbol `sym` is not cyclic.
278292 * @pre sym is not yet initialized (i.e. its type is a Completer).
279293 * @return `info` where every legal F-bounded reference is proctected
@@ -864,7 +878,7 @@ trait Checking {
864878 def javaFieldMethodPair =
865879 decl.is(JavaDefined ) && other.is(JavaDefined ) &&
866880 decl.is(Method ) != other.is(Method )
867- if (( decl.signature.clashes(other.signature) || decl. matches(other) ) && ! javaFieldMethodPair) {
881+ if (decl.matches(other) && ! javaFieldMethodPair) {
868882 def doubleDefError (decl : Symbol , other : Symbol ): Unit =
869883 if (! decl.info.isErroneous && ! other.info.isErroneous)
870884 ctx.error(DoubleDefinition (decl, other, cls), decl.sourcePos)
@@ -1130,6 +1144,21 @@ trait Checking {
11301144 case _ =>
11311145 }
11321146 }
1147+
1148+ /** Check that symbol's external name does not clash with symbols defined in the same scope */
1149+ def checkNoAlphaConflict (stats : List [Tree ])(implicit ctx : Context ): Unit = {
1150+ var seen = Set [Name ]()
1151+ for (stat <- stats) {
1152+ val sym = stat.symbol
1153+ val ename = sym.erasedName
1154+ if (ename != sym.name) {
1155+ val preExisting = ctx.effectiveScope.lookup(ename)
1156+ if (preExisting.exists || seen.contains(ename))
1157+ ctx.error(em " @alpha annotation ${'"' }$ename${'"' } clashes with other definition is same scope " , stat.sourcePos)
1158+ seen += ename
1159+ }
1160+ }
1161+ }
11331162}
11341163
11351164trait ReChecking extends Checking {
@@ -1150,7 +1179,7 @@ trait NoChecking extends ReChecking {
11501179 override def checkImplicitConversionUseOK (sym : Symbol , posd : Positioned )(implicit ctx : Context ): Unit = ()
11511180 override def checkFeasibleParent (tp : Type , pos : SourcePosition , where : => String = " " )(implicit ctx : Context ): Type = tp
11521181 override def checkInlineConformant (tree : Tree , isFinal : Boolean , what : => String )(implicit ctx : Context ): Unit = ()
1153- override def checkNoDoubleDeclaration ( cls : Symbol )(implicit ctx : Context ): Unit = ()
1182+ override def checkNoAlphaConflict ( stats : List [ Tree ] )(implicit ctx : Context ): Unit = ()
11541183 override def checkParentCall (call : Tree , caller : ClassSymbol )(implicit ctx : Context ): Unit = ()
11551184 override def checkSimpleKinded (tpt : Tree )(implicit ctx : Context ): Tree = tpt
11561185 override def checkDerivedValueClass (clazz : Symbol , stats : List [Tree ])(implicit ctx : Context ): Unit = ()
0 commit comments