dotty.tools.dotc.transform.LetOverApply.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scala3-compiler_3 Show documentation
Show all versions of scala3-compiler_3 Show documentation
scala3-compiler-bootstrapped
package dotty.tools
package dotc
package transform
import core.*
import Contexts.*, Symbols.*, Decorators.*
import MegaPhase.*
/** Rewrite `{ stats; expr}.f(args)` to `{ stats; expr.f(args) }` and
* `{ stats; expr }(args)` to `{ stats; expr(args) }` before proceeding,
* but leave closures alone. This is necessary to be able to
* collapse applies of IFTs (this is done in Erasure).
*/
class LetOverApply extends MiniPhase:
import ast.tpd.*
override def phaseName: String = LetOverApply.name
override def description: String = LetOverApply.description
override def transformApply(tree: Apply)(using Context): Tree =
tree.fun match
case Select(blk @ Block(stats, expr), name) if !expr.isInstanceOf[Closure] =>
cpy.Block(blk)(stats,
cpy.Apply(tree)(
cpy.Select(tree.fun)(expr, name), tree.args))
case Block(stats, expr) =>
cpy.Block(tree.fun)(stats,
cpy.Apply(tree)(expr, tree.args))
case _ =>
tree
end LetOverApply
object LetOverApply:
val name: String = "letOverApply"
val description: String = "lift blocks from receivers of applications"
© 2015 - 2025 Weber Informatics LLC | Privacy Policy