Open
Description
Compiler version
3.6.3
Minimized code
Using the transparent
modifier seems to break beta-reduction (it doesn't happen) for lambda functions
// Non poly example
transparent inline def apply1[B](inline f: Int => B): B = f(1)
inline def aa: Int => Int = double
def double(i: Int) = i * 2
val a = apply1(aa)
// Got: val a: Int = ((i: Int) => double(i):(Int => Int)).apply(1)
// Expected: val a: Int = double(1):Int
// Poly example
transparent inline def applyInt[B](inline f: [T] => () => B): B = f[Int]()
inline def bb: [T] => () => Int = [T] => () => myIntPoly[T]
def myIntPoly[T]: Int = 1
val b = applyInt(bb)
// Got: val b: Int = ([T >: Nothing <: Any] => () => myIntPoly[T]:([T] => () => Int)).apply[Int]()
// Expected: val b: Int = { type T = Int; myIntPoly[T] }:Int
The code was inspected using -Xprint:type,inlining
.
The expected code can reproduced by removing transparent
and fits the beta-reduction comment specification given here
scala3/compiler/src/dotty/tools/dotc/transform/BetaReduce.scala
Lines 54 to 74 in 7ac31d0
Output
See comments in minimized code.
Expectation
The beta reduction should be properly applied for transparent
methods.