Skip to content

Commit 5ad724c

Browse files
committed
Properly handle by-name function types in repl
Fixes #18756
1 parent 38559d7 commit 5ad724c

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ElimByName extends MiniPhase, InfoTransformer:
6060
override def description: String = ElimByName.description
6161

6262
override def runsAfterGroupsOf: Set[String] = Set(ExpandSAMs.name, ElimRepeated.name, RefChecks.name)
63-
// - ExpanSAMs applied to partial functions creates methods that need
63+
// - ExpandSAMs applied to partial functions creates methods that need
6464
// to be fully defined before converting. Test case is pos/i9391.scala.
6565
// - ElimByName needs to run in a group after ElimRepeated since ElimRepeated
6666
// works on simple arguments but not converted closures, and it sees the arguments
@@ -146,8 +146,9 @@ class ElimByName extends MiniPhase, InfoTransformer:
146146
else byNameClosure(arg, formalResult)
147147
case _ =>
148148
arg
149-
150-
val mt @ MethodType(_) = tree.fun.tpe.widen: @unchecked
149+
// FIXME for some reason the info transform does not work on the REPL.
150+
// As a workaround we explicitly transform it again.
151+
val mt @ MethodType(_) = transformInfo(tree.fun.tpe.widen, tree.fun.symbol): @unchecked
151152
val args1 = tree.args.zipWithConserve(mt.paramInfos)(transformArg)
152153
cpy.Apply(tree)(tree.fun, args1)
153154
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ class SpecializeFunctions extends MiniPhase {
7171
override def transformApply(tree: Apply)(using Context) =
7272
tree match {
7373
case Apply(fun: NameTree, args) if fun.name == nme.apply && args.size <= 3 && fun.symbol.maybeOwner.isType =>
74-
val argTypes = fun.tpe.widen.firstParamTypes.map(_.widenSingleton.dealias)
74+
// FIXME for some reason the info transform does not work on the REPL.
75+
// As a workaround we explicitly transform it again.
76+
val info = (new ElimByName).transformInfo(fun.tpe.widen, fun.symbol)
77+
val argTypes = info.firstParamTypes.map(_.widenSingleton.dealias)
7578
val retType = tree.tpe.widenSingleton.dealias
7679
val isSpecializable =
7780
defn.isSpecializableFunction(

compiler/test-resources/repl/i18756

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
scala> def f: ( => Int) => Int = i => i ; f(1)
2+
def f: (=> Int) => Int
3+
val res0: Int = 1
4+
scala> f(1)
5+
val res1: Int = 1

0 commit comments

Comments
 (0)