@@ -15,7 +15,7 @@ import StdNames.nme
15
15
import Contexts .Context
16
16
import Names .{Name , TermName , EmptyTermName }
17
17
import NameOps ._
18
- import NameKinds .{ClassifiedNameKind , InlineAccessorName }
18
+ import NameKinds .{ClassifiedNameKind , InlineAccessorName , UniqueName }
19
19
import ProtoTypes .selectionProto
20
20
import SymDenotations .SymDenotation
21
21
import Annotations ._
@@ -63,23 +63,13 @@ object Inliner {
63
63
// This is quite tricky, as such types can appear anywhere, including as parts
64
64
// of types of other things. For the moment we do nothing and complain
65
65
// at the implicit expansion site if there's a reference to an inaccessible type.
66
- override def transform (tree : Tree )(implicit ctx : Context ): Tree = tree match {
67
- case tree : Assign =>
68
- transform(tree.lhs) match {
69
- case lhs1 : RefTree =>
70
- lhs1.name match {
71
- case InlineAccessorName (name) =>
72
- cpy.Apply (tree)(useSetter(lhs1), transform(tree.rhs) :: Nil )
73
- case _ =>
74
- super .transform(tree)
75
- }
76
- case _ =>
77
- super .transform(tree)
78
- }
79
- case _ =>
80
- super .transform(accessorIfNeeded(tree))
81
- }
82
-
66
+ override def transform (tree : Tree )(implicit ctx : Context ): Tree =
67
+ super .transform(accessorIfNeeded(tree)) match {
68
+ case tree1 @ Assign (lhs : RefTree , rhs) if lhs.symbol.name.is(InlineAccessorName ) =>
69
+ cpy.Apply (tree1)(useSetter(lhs), rhs :: Nil )
70
+ case tree1 =>
71
+ tree1
72
+ }
83
73
}
84
74
85
75
/** Adds accessors for all non-public term members accessed
@@ -391,7 +381,8 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
391
381
case _ => tree
392
382
}}
393
383
394
- val inlineCtx = inlineContext(call)
384
+ val inlineTyper = new InlineTyper
385
+ val inlineCtx = inlineContext(call).fresh.setTyper(inlineTyper).setNewScope
395
386
// The complete translation maps references to `this` and parameters to
396
387
// corresponding arguments or proxies on the type and term level. It also changes
397
388
// the owner from the inlined method to the current owner.
@@ -401,7 +392,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
401
392
trace(i " inlining $call\n , BINDINGS = \n ${bindingsBuf.toList}% \n % \n EXPANSION = \n $expansion" , inlining, show = true ) {
402
393
403
394
// The final expansion runs a typing pass over the inlined tree. See InlineTyper for details.
404
- val expansion1 = InlineTyper .typed(expansion, pt)(inlineCtx)
395
+ val expansion1 = inlineTyper .typed(expansion, pt)(inlineCtx)
405
396
406
397
/** All bindings in `bindingsBuf` except bindings of inlineable closures */
407
398
val bindings = bindingsBuf.toList.map(_.withPos(call.pos))
@@ -421,8 +412,8 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
421
412
*/
422
413
private object InlineableArg {
423
414
lazy val paramProxies = paramProxy.values.toSet
424
- def unapply (tree : Ident )(implicit ctx : Context ): Option [Tree ] =
425
- if (paramProxies.contains(tree.tpe ))
415
+ def unapply (tree : Trees . Ident [_] )(implicit ctx : Context ): Option [Tree ] =
416
+ if (paramProxies.contains(tree.typeOpt ))
426
417
bindingsBuf.find(_.name == tree.name) match {
427
418
case Some (vdef : ValDef ) if vdef.symbol.is(Inline ) =>
428
419
Some (vdef.rhs.changeOwner(vdef.symbol, ctx.owner))
@@ -440,7 +431,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
440
431
* 4. Make sure inlined code is type-correct.
441
432
* 5. Make sure that the tree's typing is idempotent (so that future -Ycheck passes succeed)
442
433
*/
443
- private object InlineTyper extends ReTyper {
434
+ private class InlineTyper extends ReTyper {
444
435
445
436
override def ensureAccessible (tpe : Type , superAccess : Boolean , pos : Position )(implicit ctx : Context ): Type = {
446
437
tpe match {
@@ -507,6 +498,8 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
507
498
508
499
betaReduce(super .typedApply(tree, pt))
509
500
}
501
+
502
+ override def newLikeThis : Typer = new InlineTyper
510
503
}
511
504
512
505
/** Drop any side-effect-free bindings that are unused in expansion or other reachable bindings.
0 commit comments