Skip to content

Commit 39fdda2

Browse files
committed
Address review: warning on insertion
1 parent 8546a3a commit 39fdda2

File tree

7 files changed

+31
-1
lines changed

7 files changed

+31
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2727,7 +2727,15 @@ class Typer extends Namer
27272727
def adaptNoArgsOther(wtp: Type, functionExpected: Boolean): Tree = {
27282728
ctx.typeComparer.GADTused = false
27292729
val implicitFun = isImplicitFunctionRef(wtp) && !untpd.isContextualClosure(tree)
2730-
def caseCompanion = functionExpected && tree.symbol.is(Module) && tree.symbol.companionClass.is(Case)
2730+
def caseCompanion =
2731+
functionExpected &&
2732+
tree.symbol.is(Module) &&
2733+
tree.symbol.companionClass.is(Case) &&
2734+
!tree.tpe.widen.classSymbol.asClass.classParents.exists(defn.isFunctionType(_)) && {
2735+
ctx.warning("The method `apply` is inserted. The auto insertion will be deprecated, please write `" + tree.show + ".apply` explicitly.", tree.sourcePos)
2736+
true
2737+
}
2738+
27312739
if ((implicitFun || caseCompanion) &&
27322740
!isApplyProto(pt) &&
27332741
pt != AssignProto &&

tests/neg-custom-args/fatal-warnings/i6190a.check

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Error: tests/neg-custom-args/fatal-warnings/i6190b.scala:3:29 -------------------------------------------------------
2+
3 |def foo = List("1", "2").map(Rule) // error
3+
| ^^^^
4+
| The method `apply` is inserted. The auto insertion will be deprecated, please write `Rule.apply` explicitly.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
case class Rule(name: String)
2+
3+
def foo = List("1", "2").map(Rule) // error

tests/neg/i6190.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Rule(name: String)
2+
object Rule {
3+
def apply(name: String): Rule = new Rule(name)
4+
}
5+
6+
def foo = List("1", "2").map(Rule) // error
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
case class Rule(name: String)
2+
object Rule extends (String => Rule) {
3+
def apply(name: String): Rule = new Rule(name)
4+
}
5+
6+
def foo = List("1", "2").map(Rule)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
case class Rule(name: String)
2+
3+
def foo = List("1", "2").map(Rule.apply)

0 commit comments

Comments
 (0)