File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -39,11 +39,12 @@ object Inliner {
3939 */
4040 private def makeInlineable (tree : Tree )(implicit ctx : Context ) = {
4141
42+ val inlineMethod = ctx.owner
43+
4244 /** A tree map which inserts accessors for all non-public term members accessed
4345 * from inlined code. Accessors are collected in the `accessors` buffer.
4446 */
4547 object addAccessors extends TreeMap {
46- val inlineMethod = ctx.owner
4748 val accessors = new mutable.ListBuffer [MemberDef ]
4849
4950 /** A definition needs an accessor if it is private, protected, or qualified private
@@ -180,8 +181,14 @@ object Inliner {
180181 }
181182 }
182183
183- val tree1 = addAccessors.transform(tree)
184- flatTree(tree1 :: addAccessors.accessors.toList)
184+ if (inlineMethod.owner.isTerm)
185+ // Inline methods in local scopes can only be called in the scope they are defined,
186+ // so no accessors are needed for them.
187+ tree
188+ else {
189+ val tree1 = addAccessors.transform(tree)
190+ flatTree(tree1 :: addAccessors.accessors.toList)
191+ }
185192 }
186193
187194 /** Register inline info for given inline method `sym`.
Original file line number Diff line number Diff line change 1+ object Test {
2+ private def foo (arg1 : Int ): Int = {
3+ inline def bar : Int = foo(0 )
4+ if (arg1 == 0 ) 0 else bar
5+ }
6+ assert(foo(11 ) == 0 )
7+ }
You can’t perform that action at this time.
0 commit comments