@@ -3222,9 +3222,6 @@ class Typer extends Namer
32223222 * Examples for these cases are found in run/implicitFuns.scala and neg/i2006.scala.
32233223 */
32243224 def adaptNoArgsUnappliedMethod (wtp : MethodType , functionExpected : Boolean , arity : Int ): Tree = {
3225- def isExpandableApply =
3226- defn.isContextFunctionClass(tree.symbol.maybeOwner) && functionExpected
3227-
32283225 /** Is reference to this symbol `f` automatically expanded to `f()`? */
32293226 def isAutoApplied (sym : Symbol ): Boolean =
32303227 sym.isConstructor
@@ -3241,7 +3238,7 @@ class Typer extends Namer
32413238 ! tree.symbol.isConstructor &&
32423239 ! tree.symbol.isAllOf(InlineMethod ) &&
32433240 ! ctx.mode.is(Mode .Pattern ) &&
3244- ! (isSyntheticApply(tree) && ! isExpandableApply )) {
3241+ ! (isSyntheticApply(tree) && ! functionExpected )) {
32453242 if (! defn.isFunctionType(pt))
32463243 pt match {
32473244 case SAMType (_) if ! pt.classSymbol.hasAnnotation(defn.FunctionalInterfaceAnnot ) =>
@@ -3266,9 +3263,18 @@ class Typer extends Namer
32663263 defn.isContextFunctionClass(underlying.classSymbol)
32673264 }
32683265
3269- def adaptNoArgsOther (wtp : Type ): Tree = {
3270- if (isContextFunctionRef(wtp) &&
3271- ! untpd.isContextualClosure(tree) &&
3266+ def adaptNoArgsOther (wtp : Type , functionExpected : Boolean ): Tree = {
3267+ val implicitFun = isContextFunctionRef(wtp) && ! untpd.isContextualClosure(tree)
3268+ def caseCompanion =
3269+ functionExpected &&
3270+ tree.symbol.is(Module ) &&
3271+ tree.symbol.companionClass.is(Case ) &&
3272+ ! tree.tpe.widen.classSymbol.asClass.classParents.exists(defn.isFunctionType(_)) && {
3273+ report.warning(" The method `apply` is inserted. The auto insertion will be deprecated, please write `" + tree.show + " .apply` explicitly." , tree.sourcePos)
3274+ true
3275+ }
3276+
3277+ if ((implicitFun || caseCompanion) &&
32723278 ! isApplyProto(pt) &&
32733279 pt != AssignProto &&
32743280 ! ctx.mode.is(Mode .Pattern ) &&
@@ -3390,7 +3396,7 @@ class Typer extends Namer
33903396 }
33913397 adaptNoArgsUnappliedMethod(wtp, funExpected, arity)
33923398 case _ =>
3393- adaptNoArgsOther(wtp)
3399+ adaptNoArgsOther(wtp, functionExpected )
33943400 }
33953401 }
33963402
0 commit comments