Skip to content

Commit fcb6934

Browse files
committed
Fix #10966: handle local apply methods
1 parent a438ec4 commit fcb6934

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

compiler/src/dotty/tools/dotc/transform/SpecializeFunctions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class SpecializeFunctions extends MiniPhase {
6767
/** Dispatch to specialized `apply`s in user code when available */
6868
override def transformApply(tree: Apply)(using Context) =
6969
tree match {
70-
case Apply(fun: NameTree, args) if fun.name == nme.apply && args.size <= 3 =>
70+
case Apply(fun: NameTree, args) if fun.name == nme.apply && args.size <= 3 && fun.symbol.owner.isType =>
7171
val argTypes = fun.tpe.widen.firstParamTypes.map(_.widenSingleton.dealias)
7272
val retType = tree.tpe.widenSingleton.dealias
7373
val isSpecializable =

tests/pos/i10966.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
object Main {
2+
def main(args: Array[String]): Unit = {
3+
def apply(a: Int, b: Int): Unit = {}
4+
apply(1, 2)
5+
6+
// The following will work:
7+
def f(a: Int, b: Int): Unit = {}
8+
f(1, 2)
9+
}
10+
11+
def foo() = {
12+
// The following will not work either:
13+
def `apply`(a: Int): Unit = {}
14+
`apply`(1)
15+
}
16+
}

0 commit comments

Comments
 (0)