Skip to content

Fix #10966: handle local apply methods #10984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SpecializeFunctions extends MiniPhase {
/** Dispatch to specialized `apply`s in user code when available */
override def transformApply(tree: Apply)(using Context) =
tree match {
case Apply(fun: NameTree, args) if fun.name == nme.apply && args.size <= 3 =>
case Apply(fun: NameTree, args) if fun.name == nme.apply && args.size <= 3 && fun.symbol.owner.isType =>
val argTypes = fun.tpe.widen.firstParamTypes.map(_.widenSingleton.dealias)
val retType = tree.tpe.widenSingleton.dealias
val isSpecializable =
Expand Down
16 changes: 16 additions & 0 deletions tests/pos/i10966.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
object Main {
def main(args: Array[String]): Unit = {
def apply(a: Int, b: Int): Unit = {}
apply(1, 2)

// The following will work:
def f(a: Int, b: Int): Unit = {}
f(1, 2)
}

def foo() = {
// The following will not work either:
def `apply`(a: Int): Unit = {}
`apply`(1)
}
}