Skip to content

Commit 222d258

Browse files
committed
Address review: warning on insertion
1 parent f95da59 commit 222d258

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
@@ -3268,7 +3268,15 @@ class Typer extends Namer
32683268

32693269
def adaptNoArgsOther(wtp: Type, functionExpected: Boolean): Tree = {
32703270
val implicitFun = isImplicitFunctionRef(wtp) && !untpd.isContextualClosure(tree)
3271-
def caseCompanion = functionExpected && tree.symbol.is(Module) && tree.symbol.companionClass.is(Case)
3271+
def caseCompanion =
3272+
functionExpected &&
3273+
tree.symbol.is(Module) &&
3274+
tree.symbol.companionClass.is(Case) &&
3275+
!tree.tpe.widen.classSymbol.asClass.classParents.exists(defn.isFunctionType(_)) && {
3276+
ctx.warning("The method `apply` is inserted. The auto insertion will be deprecated, please write `" + tree.show + ".apply` explicitly.", tree.sourcePos)
3277+
true
3278+
}
3279+
32723280
if ((implicitFun || caseCompanion) &&
32733281
!isApplyProto(pt) &&
32743282
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)