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 {
39
39
*/
40
40
private def makeInlineable (tree : Tree )(implicit ctx : Context ) = {
41
41
42
+ val inlineMethod = ctx.owner
43
+
42
44
/** A tree map which inserts accessors for all non-public term members accessed
43
45
* from inlined code. Accessors are collected in the `accessors` buffer.
44
46
*/
45
47
object addAccessors extends TreeMap {
46
- val inlineMethod = ctx.owner
47
48
val accessors = new mutable.ListBuffer [MemberDef ]
48
49
49
50
/** A definition needs an accessor if it is private, protected, or qualified private
@@ -180,8 +181,14 @@ object Inliner {
180
181
}
181
182
}
182
183
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
+ }
185
192
}
186
193
187
194
/** 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