@@ -761,29 +761,21 @@ trait Checking {
761761 }
762762 }
763763
764- /** If `sym` is an implicit conversion, check that that implicit conversions are enabled, unless
765- * - it is synthetic
766- * - it is has the same owner as one of the classes it converts to (modulo companions)
767- * - it is defined in Predef
768- * - it is the scala.reflect.Selectable.reflectiveSelectable conversion
764+ /** If `tree` is an application of a new-style implicit conversion (using the apply
765+ * method of a `scala.Conversion` instance), check that implicit conversions are
766+ * enabled.
769767 */
770- def checkImplicitConversionUseOK (sym : Symbol , pos : SrcPos )(using Context ): Unit =
771- if (sym.exists) {
772- val conv =
773- if (sym.isOneOf(GivenOrImplicit ) || sym.info.isErroneous) sym
774- else {
775- assert(sym.name == nme.apply || ctx.reporter.errorsReported)
776- sym.owner
777- }
778- val conversionOK =
779- conv.is(Synthetic ) ||
780- sym.info.finalResultType.classSymbols.exists(_.isLinkedWith(conv.owner)) ||
781- defn.isPredefClass(conv.owner) ||
782- conv.name == nme.reflectiveSelectable && conv.maybeOwner.maybeOwner.maybeOwner == defn.ScalaPackageClass
783- if (! conversionOK)
784- checkFeature(nme.implicitConversions,
785- i " Use of implicit conversion ${conv.showLocated}" , NoSymbol , pos)
786- }
768+ def checkImplicitConversionUseOK (tree : Tree )(using Context ): Unit =
769+ val sym = tree.symbol
770+ if sym.name == nme.apply
771+ && sym.owner.derivesFrom(defn.ConversionClass )
772+ && ! sym.info.isErroneous
773+ then
774+ def conv = methPart(tree) match
775+ case Select (qual, _) => qual.symbol.orElse(sym.owner)
776+ case _ => sym.owner
777+ checkFeature(nme.implicitConversions,
778+ i " Use of implicit conversion ${conv.showLocated}" , NoSymbol , tree.srcPos)
787779
788780 private def infixOKSinceFollowedBy (tree : untpd.Tree ): Boolean = tree match {
789781 case _ : untpd.Block | _ : untpd.Match => true
@@ -1244,7 +1236,7 @@ trait NoChecking extends ReChecking {
12441236 override def checkStable (tp : Type , pos : SrcPos , kind : String )(using Context ): Unit = ()
12451237 override def checkClassType (tp : Type , pos : SrcPos , traitReq : Boolean , stablePrefixReq : Boolean )(using Context ): Type = tp
12461238 override def checkImplicitConversionDefOK (sym : Symbol )(using Context ): Unit = ()
1247- override def checkImplicitConversionUseOK (sym : Symbol , pos : SrcPos )(using Context ): Unit = ()
1239+ override def checkImplicitConversionUseOK (tree : Tree )(using Context ): Unit = ()
12481240 override def checkFeasibleParent (tp : Type , pos : SrcPos , where : => String = " " )(using Context ): Type = tp
12491241 override def checkInlineConformant (tpt : Tree , tree : Tree , sym : Symbol )(using Context ): Unit = ()
12501242 override def checkNoAlphaConflict (stats : List [Tree ])(using Context ): Unit = ()
0 commit comments