File tree 4 files changed +40
-3
lines changed
compiler/src/dotty/tools/dotc
4 files changed +40
-3
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 @@ -749,14 +749,13 @@ object Erasure {
749
749
val origFunType = origFun.tpe.widen(using preErasureCtx)
750
750
val ownArgs = if origFunType.isErasedMethod then Nil else args
751
751
val fun1 = typedExpr(fun, AnyFunctionProto )
752
- val fun1core = stripBlock(fun1)
753
752
fun1.tpe.widen match
754
753
case mt : MethodType =>
755
754
val (xmt, // A method type like `mt` but with bunched arguments expanded to individual ones
756
755
bunchArgs, // whether arguments are bunched
757
756
outers) = // the outer reference parameter(s)
758
- if fun1core .isInstanceOf [Apply ] then
759
- (mt, fun1core .removeAttachment(BunchedArgs ).isDefined, Nil )
757
+ if fun1 .isInstanceOf [Apply ] then
758
+ (mt, fun1 .removeAttachment(BunchedArgs ).isDefined, Nil )
760
759
else
761
760
val xmt = expandedMethodType(mt, origFun)
762
761
(xmt, xmt ne mt, outer.args(origFun))
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 Contexts .Context , Symbols ._ , Decorators ._
7
+ import MegaPhase ._
8
+ import ast .Trees ._
9
+
10
+ /** Rewrite `{ stats; expr}.f(args)` to `{ stats; expr.f(args) }` and
11
+ * `{ stats; expr }(args)` to `{ stats; expr(args) }` before proceeding,
12
+ * but leave closures alone. This is necessary to be able to
13
+ * collapse applies of IFTs (this is done in Erasure).
14
+ */
15
+ class LetOverApply extends MiniPhase :
16
+ import ast .tpd ._
17
+
18
+ override def phaseName : String = " letOverApply"
19
+
20
+ override def transformApply (tree : Apply )(using Context ): Tree =
21
+ tree.fun match
22
+ case Select (blk @ Block (stats, expr), name) if ! expr.isInstanceOf [Closure ] =>
23
+ cpy.Block (blk)(stats,
24
+ cpy.Apply (tree)(
25
+ cpy.Select (tree.fun)(expr, name), tree.args))
26
+ case Block (stats, expr) =>
27
+ cpy.Block (tree.fun)(stats,
28
+ cpy.Apply (tree)(expr, tree.args))
29
+ case _ =>
30
+ tree
31
+
32
+ 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