File tree 3 files changed +43
-0
lines changed
compiler/src/dotty/tools/dotc 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,7 @@ class Compiler {
93
93
new FunctionXXLForwarders , // Add forwarders for FunctionXXL apply method
94
94
new ParamForwarding , // Add forwarders for aliases of superclass parameters
95
95
new TupleOptimizations , // Optimize generic operations on tuples
96
+ new LetOverApply , // Lift blocks from receivers of applications
96
97
new ArrayConstructors ) :: // Intercept creation of (non-generic) arrays and intrinsify.
97
98
List (new Erasure ) :: // Rewrite types to JVM model, erasing all type parameters, abstract types and refinements.
98
99
List (new ElimErasedValueType , // Expand erased value types to their underlying implmementation types
Original file line number Diff line number Diff line change
1
+ package dotty .tools
2
+ package dotc
3
+ package transform
4
+
5
+ import core ._
6
+ import MegaPhase ._
7
+ import Contexts .Context
8
+ import Symbols ._ , Decorators ._ , Types ._
9
+ import ast .Trees ._
10
+ import dotty .tools .dotc .ast .tpd
11
+
12
+
13
+ import scala .collection .immutable .::
14
+
15
+
16
+ /** Rewrite `{ stats; expr}.f(args) }` to `{ stats; expr.f(args) }` before
17
+ * proceeding, but leave closures alone. This is necessary to be able to
18
+ * collapse applies of IFTs.
19
+ */
20
+ class LetOverApply extends MiniPhase :
21
+ import ast .tpd ._
22
+
23
+ override def phaseName : String = " letOverApply"
24
+
25
+ override def transformApply (tree : tpd.Apply )(using Context ): tpd.Tree =
26
+ tree.fun match
27
+ case Select (blk @ Block (stats, expr), name) if ! expr.isInstanceOf [Closure ] =>
28
+ cpy.Block (blk)(stats,
29
+ cpy.Apply (tree)(
30
+ cpy.Select (tree.fun)(expr, name), tree.args))
31
+ case Block (stats, expr) =>
32
+ cpy.Block (tree.fun)(stats,
33
+ cpy.Apply (tree)(expr, tree.args))
34
+ case _ =>
35
+ tree
36
+
37
+ end LetOverApply
Original file line number Diff line number Diff line change
1
+ object Crash {
2
+ def f (a : String , b : String , c : Int = 0 ): Int ?=> String = " "
3
+ given Int = ???
4
+ f(b = " b" , a = " a" )
5
+ }
You can’t perform that action at this time.
0 commit comments