Skip to content

Commit

Permalink
Properly handle by-name function types in repl
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Oct 25, 2023
1 parent 38559d7 commit 9b9a4c7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/ElimByName.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ElimByName extends MiniPhase, InfoTransformer:
override def description: String = ElimByName.description

override def runsAfterGroupsOf: Set[String] = Set(ExpandSAMs.name, ElimRepeated.name, RefChecks.name)
// - ExpanSAMs applied to partial functions creates methods that need
// - ExpandSAMs applied to partial functions creates methods that need
// to be fully defined before converting. Test case is pos/i9391.scala.
// - ElimByName needs to run in a group after ElimRepeated since ElimRepeated
// works on simple arguments but not converted closures, and it sees the arguments
Expand Down Expand Up @@ -147,7 +147,7 @@ class ElimByName extends MiniPhase, InfoTransformer:
case _ =>
arg

val mt @ MethodType(_) = tree.fun.tpe.widen: @unchecked
val mt @ MethodType(_) = transformInfo(tree.fun.tpe.widen, tree.fun.symbol): @unchecked
val args1 = tree.args.zipWithConserve(mt.paramInfos)(transformArg)
cpy.Apply(tree)(tree.fun, args1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class SpecializeFunctions extends MiniPhase {
override def transformApply(tree: Apply)(using Context) =
tree match {
case Apply(fun: NameTree, args) if fun.name == nme.apply && args.size <= 3 && fun.symbol.maybeOwner.isType =>
val argTypes = fun.tpe.widen.firstParamTypes.map(_.widenSingleton.dealias)
val info = (new ElimByName).transformInfo(fun.tpe.widen, fun.symbol)
val argTypes = info.firstParamTypes.map(_.widenSingleton.dealias)
val retType = tree.tpe.widenSingleton.dealias
val isSpecializable =
defn.isSpecializableFunction(
Expand Down
5 changes: 5 additions & 0 deletions compiler/test-resources/repl/i18756
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
scala> def f: ( => Int) => Int = i => i ; f(1)
def f: (=> Int) => Int
val res0: Int = 1
scala> f(1)
val res1: Int = 1

0 comments on commit 9b9a4c7

Please sign in to comment.