Skip to content

Commit d704b5c

Browse files
committed
Address review: warning on insertion
1 parent f895739 commit d704b5c

File tree

7 files changed

+35
-1
lines changed

7 files changed

+35
-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
@@ -2723,7 +2723,15 @@ class Typer extends Namer
27232723
def adaptNoArgsOther(wtp: Type, functionExpected: Boolean): Tree = {
27242724
ctx.typeComparer.GADTused = false
27252725
val implicitFun = isImplicitFunctionRef(wtp) && !untpd.isContextualClosure(tree)
2726-
def caseCompanion = functionExpected && tree.symbol.is(Module) && tree.symbol.companionClass.is(Case)
2726+
def caseCompanion =
2727+
functionExpected &&
2728+
tree.symbol.is(Module) &&
2729+
tree.symbol.companionClass.is(Case) &&
2730+
!tree.tpe.widen.classSymbol.asClass.classParents.exists(defn.isFunctionType(_)) && {
2731+
ctx.warning("The method `apply` is inserted. The auto insertion will be deprecated, please write `" + tree.show + ".apply` explicitly.", tree.sourcePos)
2732+
true
2733+
}
2734+
27272735
if ((implicitFun || caseCompanion) &&
27282736
!isApplyProto(pt) &&
27292737
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
case class Rule(name: String)
2+
3+
def foo = List("1", "2").map(Rule) // error
4+

tests/neg/i6190.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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
7+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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)
7+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
case class Rule(name: String)
2+
3+
def foo = List("1", "2").map(Rule.apply)
4+

0 commit comments

Comments
 (0)